Permalink
Browse files

fix(repository): Mark entities as clean upon calling .find()

  • Loading branch information...
RWOverdijk committed Jan 6, 2016
1 parent c996c27 commit b689329e4b2c08ab63752959c0be83f9cb26fecd
Showing with 23 additions and 6 deletions.
  1. +23 −6 src/repository.js
@@ -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;
});
}
/**
@@ -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;
@@ -128,7 +139,7 @@ export class Repository {
populatedData[key] = repository.populateEntities(value);
}
return entity.setData(populatedData).markClean();
return entity.setData(populatedData);
}
/**
@@ -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;

0 comments on commit b689329

Please sign in to comment.