Skip to content

Commit

Permalink
fix: allow id = 0 in upsert
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-bechara committed Jun 14, 2021
1 parent ade8e5c commit 5ac4855
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions source/orm/orm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,14 @@ export abstract class OrmService<Entity> {
for (const key in sampleData) Array.isArray(sampleData[key]) ? populate.push(key) : undefined;
const matchingEntities = await this.read({ $or: clauses }, { populate });

// Remap matches to original ordering
// Find matching entities for each item on original data
const matches = dataArray.map((data, i) => {
const entity = matchingEntities.filter((e: any) => {
// Iterate each property of unique key definition
for (const key in clauses[i]) {
if (e[key]?.id) {
if (clauses[i][key]?.id) {
// If it references a nested entity, allow to match its .id directly with property
if (e[key]?.id || e[key]?.id === 0) {
if (clauses[i][key]?.id || clauses[i][key]?.id === 0) {
if (e[key].id !== clauses[i][key].id) return false;
}
else {
Expand Down

0 comments on commit 5ac4855

Please sign in to comment.