Permalink
Browse files

fix(entity): use getId for collections

  • Loading branch information...
doktordirk committed Jul 7, 2016
1 parent 6d2f9b1 commit 224cade6465b83a2b1b7ce47dc72ab8ac094f5bd
Showing with 13 additions and 9 deletions.
  1. +12 −8 src/entity.js
  2. +1 −1 test/entity.spec.js
@@ -513,10 +513,12 @@ function asObject(entity, shallow) {
return;
}
if (value.id) {
pojo[propertyName] = value.id; // weird. entities always have an id!?
} else if (value instanceof Entity) {
pojo[propertyName] = value.asObject();
if (value instanceof Entity) {
if (value.getId()) {
pojo[propertyName] = value.getId();
} else {
pojo[propertyName] = value.asObject();
}
} else if (['string', 'number', 'boolean'].indexOf(typeof value) > -1 || value.constructor === Object) {
pojo[propertyName] = value;
}
@@ -612,10 +614,12 @@ function getCollectionsCompact(forEntity, includeNew) {
return;
}
if (entity.id) {
collections[index].push(entity.id); // again weird. see above
} else if (includeNew && entity instanceof Entity) {
collections[index].push(entity);
if (entity instanceof Entity) {
if (entity.getId()) {
collections[index].push(entity.getId());
} else if (includeNew) {
collections[index].push(entity);
}
}
});
});
@@ -474,7 +474,7 @@ describe('Entity', function() {
describe('.setId()', function() {
it(`Should set the entity's id`, function() {
let instance = new WithResource();
instance.setId(1)
instance.setId(1);
expect(instance.idTag).toBe(1);
});

0 comments on commit 224cade

Please sign in to comment.