Skip to content

Commit

Permalink
Only normalize the hint once.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed May 7, 2024
1 parent 4423ce8 commit c53a246
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/orm/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,21 @@ export async function toJSON<T extends Entity, const H extends JsonHint<T>>(
const entity = Array.isArray(entityOrList) ? entityOrList[0] : entityOrList;
const loadHint = convertToLoadHint(getMetadata(entity), hint as any, true);
await entity.em.populate(entityOrList, loadHint);
const normHint = normalizeHint(hint as any);

if (Array.isArray(entityOrList)) {
const list = [] as any;
await Promise.all(
entityOrList.map((entity) => {
const json = {};
list.push(json);
return copyToPayload(json, entity, normalizeHint(hint as any));
return copyToPayload(json, entity, normHint);
}),
);
return list;
} else {
const json = {};
await copyToPayload(json, entity, normalizeHint(hint as any));
await copyToPayload(json, entity, normHint);
return json as any;
}
}
Expand Down

0 comments on commit c53a246

Please sign in to comment.