Skip to content

Commit

Permalink
fix(core): merge only objects in assign() with mergeObjects flag
Browse files Browse the repository at this point in the history
  • Loading branch information
B4nan committed Apr 6, 2019
1 parent 48f001c commit 749ca6f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/entity/EntityAssigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class EntityAssigner {
return entity[prop as keyof T] = entity.__em.getValidator().validateProperty(props[prop], value, entity);
}

if (options.mergeObjects) {
if (options.mergeObjects && Utils.isObject(value)) {
Utils.merge(entity[prop as keyof T], value);
} else {
entity[prop as keyof T] = value;
Expand Down
3 changes: 3 additions & 0 deletions tests/EntityHelper.mysql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ describe('EntityHelperMySql', () => {
expect(book.meta).toEqual({ items: 3, category: 'bar' });
book.assign({ meta: { category: 'bar' } });
expect(book.meta).toEqual({ category: 'bar' });
jon.identities = ['1', '2'];
jon.assign({ identities: ['3', '4'] }, { mergeObjects: true });
expect(jon.identities).toEqual(['3', '4']);
});

afterAll(async () => orm.close(true));
Expand Down

0 comments on commit 749ca6f

Please sign in to comment.