0

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)?

Lior Elrom
  • 19,660
  • 16
  • 80
  • 92
wobbily_col
  • 11,390
  • 12
  • 62
  • 86

1 Answers1

0

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.

wobbily_col
  • 11,390
  • 12
  • 62
  • 86