Skip to content

Commit

Permalink
Change uses of id to call url(), so url building will continue to…
Browse files Browse the repository at this point in the history
… work as expected when using a different idAttribute. Fixes #20
  • Loading branch information
PaulUithol committed Oct 26, 2013
1 parent 84acd7b commit 47a9253
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions backbone_tastypie/static/js/backbone-tastypie.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
// If create is successful but doesn't return a response, fire an extra GET.
// Otherwise, resolve the deferred (which triggers the original 'success' callbacks).
if ( !resp && ( xhr.status === 201 || xhr.status === 202 || xhr.status === 204 ) ) { // 201 CREATED, 202 ACCEPTED or 204 NO CONTENT; response null or empty.
var location = xhr.getResponseHeader( 'Location' ) || model.id;
var location = xhr.getResponseHeader( 'Location' ) || model.url();
return Backbone.ajax({
url: location,
headers: headers,
Expand Down Expand Up @@ -100,8 +100,8 @@
Backbone.Model.prototype.idAttribute = 'resource_uri';

Backbone.Model.prototype.url = function() {
// Use the id if possible
var url = this.id;
// Use the 'resource_uri' if possible
var url = this.get( 'resource_uri' );

// If there's no idAttribute, use the 'urlRoot'. Fallback to try to have the collection construct a url.
// Explicitly add the 'id' attribute if the model has one.
Expand Down Expand Up @@ -151,7 +151,7 @@
// (set to 'resource_uri') contains the model's id.
if ( models && models.length ) {
var ids = _.map( models, function( model ) {
var parts = _.compact( model.id.split( '/' ) );
var parts = _.compact( model.url().split( '/' ) );
return parts[ parts.length - 1 ];
});
url += 'set/' + ids.join( ';' ) + '/';
Expand Down
2 changes: 1 addition & 1 deletion test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ $(document).ready(function() {

ok( window.requests.length === 2 );
equal( _.last( window.requests ).headers[ 'Authorization' ], 'ApiKey daniel:204db7bcfafb2deb7506b89eb3b9b715b09905c8' );
ok( animal.id === '/animal/1/' );
equal( animal.id, '/animal/1/' );
});

test( "CSRF token sent as an extra header", function() {
Expand Down

0 comments on commit 47a9253

Please # to comment.