Skip to content

Commit

Permalink
make sure the new id fetching logic is used in all places
Browse files Browse the repository at this point in the history
  • Loading branch information
Burgov committed May 10, 2014
1 parent a2f4ded commit b8d1645
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/ObjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,9 @@ var ObjectManager = function(proxyFactory) {
return null;
}

var schemaConstructor = entityClassMap[entityName].prototype.$schema.constructor;
var idProperty = 'id' in schemaConstructor ? schemaConstructor.id : 'id';

var map = objectMap[entityName];
for (var i in map) {
if (map[i][idProperty] == id) {
if (map[i][ObjectManager.getIdProperty(entityClassMap[entityName])] == id) {
return map[i];
}
}
Expand Down Expand Up @@ -195,7 +192,7 @@ var ObjectManager = function(proxyFactory) {
return entity;
}

var existing = getFromObjectMap(entityName, data.id);
var existing = getFromObjectMap(entityName, data[ObjectManager.getIdProperty(entityClassMap[entityName])]);
if (null !== existing) {
if (!(this.isProxy(existing))) {
this.update(existing, data);
Expand Down Expand Up @@ -318,3 +315,8 @@ Object.defineProperty(ObjectManager, 'prepareEntity', {
});
}
});

Object.defineProperty(ObjectManager, 'getIdProperty', { value: function(entityClass) {
var schemaConstructor = entityClass.prototype.$schema.constructor;
return 'id' in schemaConstructor ? schemaConstructor.id : 'id';
} });
6 changes: 4 additions & 2 deletions src/Proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ var ProxyFactory = function() {
})
}

var idProperty = ObjectManager.getIdProperty(entityClass);

for (var i in entityClass.prototype.$schema) {
if (i == 'id') {
if (i == idProperty) {
continue;
}

this.addProperty(i);
}

Object.defineProperty(this, 'id', {
Object.defineProperty(this, idProperty, {
get: function() {
return id;
},
Expand Down

0 comments on commit b8d1645

Please sign in to comment.