Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Updated to support MongoDB which uses "_id" property instead of "id" #7

wants to merge 1 commit into from

2 participants


No description provided.


Thanks for the PR. I've heard from other MongoDB users who were tripped up by _id and I'd be glad to make ember-rest more compatible.

For consistency, I'd prefer to go with _resourceId() instead of _recordId().

Also, return this.get('id') || this.get('_id'); will be a slight performance hit for MongoDB users. You'd be better off to override _resourceId() for every Ember.Resource like this:

  _resourceId: function() {
    return this.get('_id');

I'd prefer to just support the one default id scheme and let people override it as needed.

If you want to modify this PR and rebase, I'd be glad to merge it. Otherwise, I could make these tweaks for you quickly. Just let me know.


Maybe it would be good that "primary key" is just property somewhere like 'resourcePrimaryKey' or something .. ?

If it's ok to you, please make these tweaks. Thanks :)


@vizo Good suggestion! I introduced a new resourceIdField, which is set to id by default. This should be even easier to override in your models. I also renamed _id() to _resourceId() as discussed.

See this commit for all the details.

@dgeb dgeb closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2012
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 4 deletions.
  1. +4 −4 src/ember-rest.js
8 src/ember-rest.js
@@ -174,7 +174,7 @@ Ember.Resource = Ember.Object.extend({
Is this a new resource?
isNew: function() {
- return (this._id() === undefined);
+ return (this._recordId() === undefined);
@@ -185,7 +185,7 @@ Ember.Resource = Ember.Object.extend({
_resourceUrl: function() {
var url = this.resourceUrl,
- id = this._id();
+ id = this._recordId();
if (id !== undefined)
url += '/' + id;
@@ -198,8 +198,8 @@ Ember.Resource = Ember.Object.extend({
The id for this resource.
- _id: function() {
- return this.get('id');
+ _recordId: function() {
+ return this.get('id') || this.get('_id');
Something went wrong with that request. Please try again.