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

Commit

Permalink
fix(repository): Mark entities as clean upon calling .find()
Browse files Browse the repository at this point in the history
  • Loading branch information
RWOverdijk committed Jan 6, 2016
1 parent c996c27 commit b689329
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@ export class Repository {
return findQuery;
}

return findQuery.then(x => this.populateEntities(x));
return findQuery
.then(x => this.populateEntities(x))
.then(populated => {
if (!Array.isArray(populated)) {
return populated;
}

populated.forEach(entity => entity.markClean());

return populated;
});
}

/**
Expand Down Expand Up @@ -100,12 +110,13 @@ export class Repository {
}

/**
* @param {{}} data
* @param {{}} data
* @param {Entity} entity
*
* @return {Entity}
*/
getPopulatedEntity(data) {
let entity = this.getNewEntity();
getPopulatedEntity(data, entity) {
entity = entity || this.getNewEntity();
let entityMetadata = entity.getMeta();
let populatedData = {};
let key;
Expand All @@ -128,7 +139,7 @@ export class Repository {
populatedData[key] = repository.populateEntities(value);
}

return entity.setData(populatedData).markClean();
return entity.setData(populatedData);
}

/**
Expand All @@ -150,7 +161,13 @@ export class Repository {
let associations = entity.getMeta().fetch('associations');

for (let property in associations) {
entity[property] = this.entityManager.getRepository(associations[property].entity).getNewEntity();
let assocMeta = associations[property];

if (assocMeta.type !== 'entity') {
continue;
}

entity[property] = this.entityManager.getRepository(assocMeta.entity).getNewEntity();
}

return entity;
Expand Down

0 comments on commit b689329

Please sign in to comment.