How to set relational attributes on new model with Backbone-relational - rest

I am building a JavaScript app, and have been learning JavaScript and Backbone, and have added Backbone-relational to it. It saves to a Django-tastypie REST server.
So before I was using Backbone-relational, I would create a new object, and either set the attributes when it was created, by passing them to the constructor, or passing a dictionary of attributes to the save() method.
e.g in CoffeeScript:
myModel.save {attribute:value , foreignKey_attribute : '/api/resourceUri/'}
success ->
....
Now I have switched to Backbone-relational, it solves a lot of problems fetching the data, but I cant seem to set the foreign key attribute as before.
Either passing the dictionary to the constructor, or the save method. When I look at the object in the console, or the contents of the POST, the foreign_key attribute is always null.
Is there a way around this, or another way of setting the foreign_key_attribute (given that I have the foreign key id)?

Ok, worked it out.
Rather than trying to set the flowcell to a resource_uri string, set it as the flowcell object.
Then in the relations I needed to set the following:
includeInJSON: 'resource_uri'
This serialzes the object the way the tastypie back end expects it.

Related

How can I read out the "glade ID" of a gtk3 object

In glade it is possible to set an unique ID to an object. In the code one can obtain a pointer to this object by searching for it's "glade ID" via gtk_builder_get_object().
However for my current use-case I just want to read out this ID from an GObject. What's the API to do so ?
You can't. The builder ID is stored in the builder internally, not in the GObject.
The reason for this is that IDs must be unique per builder, which would be impossible to enforce if you were able to get and set them via some GObject API.
You could use gtk_widget_get_name() to identify an object.
It is possible using Gtk.Buildable.get_name(object). This method will return the Glade object id.
This snippet will print all object ids in your Glade XML:
builder = Gtk.Builder()
builder.add_from_file("my-window.glade"))
for obj in builder.get_objects():
print(Gtk.Buildable.get_name(obj))
As stated by #ptomato it's seems not possible.
I found that in that line in the documentation:
All the fields in the GObject structure are private to the
implementation and should never be accessed directly.
But you can circumvent it because at one point in your code you were refering to it by the id that you typed in (or the code you wrote type in) so you just need to store it at that point. And link it somehow (with a variable or a data structure) to the name of the variable holding the object.

Persisting objects in objects using spring-data

For the first time i am trying to use spring-data.
Everything works fine when i'm using object that has simple objects.
Now i'm trying to add Location object to User class.
User creation works fine (i use POST request to /users).
But when i try to add location (using PUT or PATCH to /users/1/locations) then comes 201 CREATED status, but no location is added (checked with GET /users/1/locations).
Source code is very simple and is accesible under this link.
Thanks for help in advance
Have you tried annotating your Location class with #Embeddable and your location variable inside the User class with #Embedded? You need to do this in order to force an object to be stored inside of another in the database.

MagicalRecord: How to import values into a related entity

I'm using a web service which returns results like the following example:
{
"name":"Frank",
"meals":[
"cheeseburger",
"lasagne"
]
}
My Core Data schema looks like this:
Using MagicalRecord's MR_importValuesForKeysWithObject method, how would I set about mapping the meals key to the related Meals.name attribute?
I can map the meals manually after, using a for in loop, but just wondered if there was a way MR_importValuesForKeysWithObject would perform this for me?
Basically I want each object in the JSON "meals" array to become a new Meals entity.
Override importMeals: on the Person object and do the lookup/create/associate manually.
(longer answer)
every property imported via MagicalRecord calls import(PropertyName) on the target object, by implementing it you can override functionality.

Symfony get form model object

In my symfony application I would like to get form model object before calling save method.For example: on form submit I bind it to the related Form Object. And before calling save method I want to get related Model object with its submitted values.I know there is $this->form->getObject() method.When I call it before $this->form->save(); method it returns model without values. Is there any way to get it? Any help is appreciated.
Thanks in advance!
The form's values are only set in the object in save(). You have two options:
if the values are enough, use $form->getValues(), it returns the cleaned array
if they aren't, call $form->updateObject() manually.

Business Logic when Saving in Entity Framework

If I want to perform some action when an entity is saved, I can do something as described here.
However, suppose I retrieve an object from the database. This object has a list of items within it. If I instantiate a new item and add it to this list and then save all changes, the item in the list is not part of the "GetObjectStateEntries".
The problem for my situation, I believe, has been resolved. There appears to be a bug, in my opinion, in the ObjectContext.SaveChanges(SaveOptions) method. Even though this method will call DetectChanges (depending on the saveOptions), the OnSavingChanges method is called FIRST. This, I think, is a problem.
The solution to this is to call ObjectContext.DetectChanges() prior to calling SaveChanges().