Skip to content

Commit

Permalink
fix(mikro): recursively unwrap collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Chau Tran authored and Chau Tran committed Mar 5, 2022
1 parent 949eb2b commit a445b3b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/mikro/src/lib/utils/serialize-entity.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ export function serializeEntity(item: AnyEntity) {

const value = item[key as string];
if (Utils.isCollection(value)) {
result[key] =
result[key] = (
(value.isInitialized(true) ? value.getItems() : value.getSnapshot()) ||
[];
[]
).map((collectionItem) => {
if (Utils.isEntity(collectionItem))
return serializeEntity(collectionItem);
if (Reference.isReference(collectionItem))
return collectionItem.toJSON();
return collectionItem;
});
} else if (Utils.isEntity(value)) {
result[key] = serializeEntity(value);
} else if (Reference.isReference(value)) {
Expand Down

0 comments on commit a445b3b

Please sign in to comment.