Skip to content

Commit

Permalink
fix(mikro): assign id before serialize entity
Browse files Browse the repository at this point in the history
  • Loading branch information
Chau Tran authored and Chau Tran committed Feb 25, 2022
1 parent f783f15 commit 068d25b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/mikro/src/lib/utils/instantiate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export function instantiate<TModel extends Dictionary<TModel>>(
}

// get the value at the current key
let valueAtKey = get(instance as Record<string, unknown>, key);

if (defaultValue !== undefined && valueAtKey === undefined) {
valueAtKey = get(defaultValue, key);
}
const valueAtKey = get(instance as Record<string, unknown>, key);

// call the meta fn to get the metaResult of the current key
const metaResult = meta();
Expand Down
5 changes: 5 additions & 0 deletions packages/mikro/src/lib/utils/serialize-entity.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function serializeEntity(item: AnyEntity) {
if (typeof key === 'symbol') {
continue;
}

const value = item[key as string];
if (isCollection(value)) {
result[key] = value.getSnapshot();
Expand All @@ -18,5 +19,9 @@ export function serializeEntity(item: AnyEntity) {
}
}

if (result['id'] == null && item['id'] != null) {
result['id'] = item['id'];
}

return result;
}

0 comments on commit 068d25b

Please sign in to comment.