Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating records: /put doesn't send record id #1548

Closed
gopeter opened this issue Dec 5, 2013 · 4 comments
Closed

Updating records: /put doesn't send record id #1548

gopeter opened this issue Dec 5, 2013 · 4 comments

Comments

@gopeter
Copy link

gopeter commented Dec 5, 2013

I'm trying to update records over my API, but Ember doesn't send the ID of the record.
I'm using Ember 1.2.0 and Ember Data 1.0.0 Beta 4
Thats my code:

this.store.find('customer', 1).then(function(data) {
      data.set('id', 1);
      data.set('name', data.name);
      data.set('initial', data.initial);
      data.set('description', data.description);
      data.save();
});

Now Ember sends a put request to my API, but sends this data only:

customer:{name:11, initial:11, description:null}}

But my API needs the ID to update the correct record. Shouldn't Ember Data always include the ID when sending put requests?

@recipher
Copy link

recipher commented Dec 5, 2013

Shouldn't the api call be something like /customer/:id ? And you can pull
the id from the URL, rather than the body?

On 5 December 2013 14:50, Peter Göbel notifications@github.com wrote:

I'm trying to update records over my API, but Ember doesn't send the ID of
the record.
I'm using Ember 1.2.0 and Ember Data 1.0.0 Beta 4
Thats my code:

this.store.find('customer', 1).then(function(data) {
data.set('id', 1);
data.set('name', data.name);
data.set('initial', data.initial);
data.set('description', data.description);
data.save();
});

Now Ember sends a put request to my API, but sends this data only:

customer:{name:11, initial:11, description:null}}

But my API needs the ID to update the correct record. Shouldn't Ember Data
always include the ID when sending put requests?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1548
.

@gopeter
Copy link
Author

gopeter commented Dec 5, 2013

Oh my god, sorry, I have to take a break now :)

@gopeter gopeter closed this as completed Dec 5, 2013
@otac0n
Copy link

otac0n commented Jun 16, 2014

Well, some existing APIs need the ID to come in, and I'd rather not proxy the request. Is it possible to make this an extend() option on RESTAdapter?

@bmac
Copy link
Member

bmac commented Jun 16, 2014

@otac0n The easiest way to force Ember Data to always include the id would be to extend the RESTSerializer like this:

App.ApplicationSerializer = DS.RESTSerializer.extend({
  serialize: function(record, options) {
    options = options || {includeId: true};
    return this._super(record, options);
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants