Permalink
Browse files

feat(repository): allow populating clean entities

  • Loading branch information...
RWOverdijk committed Feb 1, 2017
1 parent b1c0abe commit 3fe5acb5888d8b54c5f0ad8560eea5fc3f9153ed
Showing with 10 additions and 8 deletions.
  1. +10 −8 src/repository.js
@@ -162,22 +162,23 @@ export class Repository {
* Get new populated entity or entities based on supplied data including associations
*
* @param {{}|[{}]} data|[data] The data to populate with
* @param {boolean} [clean] Mark the entities as clean or not
*
* @return {Entity|[Entity]}
*/
populateEntities(data) {
populateEntities(data, clean) {
if (!data) {
return null;
}
if (!Array.isArray(data)) {
return this.getPopulatedEntity(data);
return this.getPopulatedEntity(data, null, clean);
}
let collection = [];
data.forEach(source => {
collection.push(this.getPopulatedEntity(source));
collection.push(this.getPopulatedEntity(source, null, clean));
});
return collection;
@@ -186,12 +187,13 @@ export class Repository {
/**
* Populate a (new) entity including associations
*
* @param {{}} data The data to populate with
* @param {Entity} [entity] optional. if not set, a new entity is returned
* @param {{}} data The data to populate with
* @param {Entity} [entity] optional. if not set, a new entity is returned
* @param {boolean} [clean] Mark the entities as clean or not
*
* @return {Entity}
*/
getPopulatedEntity(data, entity) {
getPopulatedEntity(data, entity, clean) {
entity = entity || this.getNewEntity();
let entityMetadata = entity.getMeta();
let populatedData = {};
@@ -219,10 +221,10 @@ export class Repository {
let repository = this.entityManager.getRepository(entityMetadata.fetch('associations', key).entity);
populatedData[key] = repository.populateEntities(value);
populatedData[key] = repository.populateEntities(value, true);
}
return entity.setData(populatedData);
return entity.setData(populatedData, clean);
}
/**

0 comments on commit 3fe5acb

Please sign in to comment.