PaulUithol/backbone-tastypie — Issue #12: Putting a model with new nested resources wont update resource_uri
Author: adamscybot
Created: 2012-02-27 16:02:04+00:00
State: open

There is a fundamental problem in backbone-tastypie which assumes that a GET needs to be triggered only when doing a POST.

There is a case whereby PUTting a resource also needs to trigger an extra GET. Lets say for example we start by GETting this model, model A, from the server:

{
name: 'adam',
email: 'adam@test.com',
resource_uri: '/api/rest/user/45/',
manages: [
{
name: 'ben',
email: 'ben@test.com',
resource_uri: '/api/rest/user/1/'
}
]
}

We now add an extra "manages" entry like so:

{
name: 'adam',
email: 'adam@test.com',
resource_uri: '/api/rest/user/45/',
manages: [
{
name: 'ben',
email: 'ben@test.com',
resource_uri: '/api/rest/user/1/'
},
{
name: 'pete',
email: 'pete@test.com'
},
]
}

We now do a PUT on the model A. Note that this is a PUT not a POST as model A already exists, we have just added an extra nested model to the manages attribute.

Now backbone-tastypie has sucessfully PUTTed. However, a GET is not triggered. This means that the resource_uri of "pete" is never added to the client side model representation.

This poses a problem for applications that dont reload the page often. E.g., if I create "pete" and the user wants to delete it straight away. This can't be done, because the resource URI is not known.