saveResource() always a POST #4

Closed
hagope opened this Issue Feb 22, 2012 · 5 comments

Comments

Projects
None yet
3 participants

hagope commented Feb 22, 2012

I'd like to update paramaters, for example set a field true to false, however, whenever I call saveResource(), I am creating a new record in the database rather than update an existing one.

Owner

dgeb commented Feb 22, 2012

saveResource currently checks the id attribute to determine whether the record is new or existing:

https://github.com/cerebris/ember-rest/blob/master/src/ember-rest.js#L121

Are you using a field other than id? I suppose that it would be better for Ember.Resource to use id as a default that could be overridden.

Owner

dgeb commented Feb 27, 2012

I've added an isNew() method to Ember.Resource that controls whether saveResource() executes with a PUT or POST. I've also added an _id() method in case you're using a field other than id. Both methods can be overridden to provide finer control of Ember.Resource, if needed.

@dgeb dgeb closed this Feb 27, 2012

hagope commented Mar 5, 2012

Okay great thanks, actually I was using an _id because that is the ID field for MongoDB, this seems like it should solve the issue, but I have yet to test it, thanks!

tardate commented Mar 18, 2012

Tried this with mongoid 2.4.6 & rails 3.2, and it works nicely

Owner

dgeb commented Mar 18, 2012

@tardate glad to hear it - thanks for the feedback! FYI: I committed another change about a week ago, which renames _id() -> _resourceId() (to avoid naming conflicts) and introduces a new resourceIdField. Just thought I'd let you know in case you weren't working with the latest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment