Skip to content

Commit

Permalink
Fix many-to-one
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Oct 16, 2024
1 parent 3fbe937 commit b6874f5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/backend-core/src/sql/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,19 @@ class InternalBuilder {
}
})
} else {
const toKey = `${toAlias}.${relationship.to}`
const foreignKey = `${fromAlias}.${relationship.from}`
// "join" to the main table, making sure the ID matches that of the main
subQuery = subQuery.where(
`${toAlias}.${relationship.to}`,
toKey,
"=",
mainKnex.raw(this.quotedIdentifier(foreignKey))
)

query = query.where(q => {
q.whereExists(whereCb(updatedKey, subQuery))
q.whereExists(whereCb(updatedKey, subQuery.clone()))
if (allowEmptyRelationships) {
q.orWhereNull(foreignKey)
q.orWhereNotExists(subQuery)
}
})
}
Expand Down

0 comments on commit b6874f5

Please sign in to comment.