Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(entity): use getId for collections
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Jul 7, 2016
1 parent 6d2f9b1 commit 224cade
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/entity.js
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/entity.spec.js
Expand Up @@ -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);
});
Expand Down

0 comments on commit 224cade

Please sign in to comment.