Permalink
Browse files

fix(populate): add date support and fix populate logic bugs

  • Loading branch information...
RWOverdijk committed Feb 7, 2017
1 parent 62cc153 commit 841fa238dc2d4ba58c9e6ed9d1f9784853dbd1c5
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/Populate.ts
@@ -107,7 +107,7 @@ export class Populate {
return this.entityManager.getReference(Entity, data, false) as T;
}
if (data[primary]) {
if (data && data[primary]) {
// Get the reference (from identity map or mocked)
base = this.entityManager.getReference(Entity, data[primary]) as T;
@@ -130,14 +130,19 @@ export class Populate {
// Only relationships require special treatment. This isn't one, so just assign and move on.
if (!field.relationship) {
if (['date', 'dateTime', 'datetime', 'time'].indexOf(field.type) > -1 && !(data[property] instanceof Date)) {
data[property] = new Date(data[property]);
}
base[property] = data[property];
return;
}
// Should we remove a relationship?
if (!data[property]) {
delete base[property];
if (base[property]) {
delete base[property];
}
return;
}
@@ -146,6 +151,10 @@ export class Populate {
return;
}
if (Array.isArray(data[property]) && !data[property].length && (!base[property] || !base[property].length)) {
return;
}
let level = recursive;
if (typeof level === 'number') {
@@ -156,7 +165,7 @@ export class Populate {
if (Array.isArray(data[property])) {
base[property] = this.assignCollection(targetConstructor, data[property], base[property], level);
} else {
} else if (data[property]) {
base[property] = this.assign(targetConstructor, data[property], base[property], level);
}
});

0 comments on commit 841fa23

Please sign in to comment.