Fix for #4431 - converting SQL joins back to left joins, syntax specifying join type as string is old which doesn't work in latest versions of knex.
This commit is contained in:
parent
a5cec7207c
commit
03822c7223
|
@ -541,7 +541,7 @@ module External {
|
|||
if (!linkTable || !linkPrimary) {
|
||||
return
|
||||
}
|
||||
const rows = related[key].rows || []
|
||||
const rows = related[key]?.rows || []
|
||||
const found = rows.find(
|
||||
(row: { [key: string]: any }) =>
|
||||
row[linkPrimary] === relationship.id ||
|
||||
|
|
|
@ -210,24 +210,18 @@ class InternalBuilder {
|
|||
const { toTable, throughTable } = JSON.parse(key)
|
||||
if (!throughTable) {
|
||||
// @ts-ignore
|
||||
query = query.join(
|
||||
toTable,
|
||||
function () {
|
||||
query = query.leftJoin(toTable, function () {
|
||||
for (let relationship of relationships) {
|
||||
const from = relationship.from,
|
||||
to = relationship.to
|
||||
// @ts-ignore
|
||||
this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
|
||||
}
|
||||
},
|
||||
"left"
|
||||
)
|
||||
})
|
||||
} else {
|
||||
query = query
|
||||
// @ts-ignore
|
||||
.join(
|
||||
throughTable,
|
||||
function () {
|
||||
.leftJoin(throughTable, function () {
|
||||
for (let relationship of relationships) {
|
||||
const fromPrimary = relationship.fromPrimary
|
||||
const from = relationship.from
|
||||
|
@ -238,21 +232,15 @@ class InternalBuilder {
|
|||
`${throughTable}.${from}`
|
||||
)
|
||||
}
|
||||
},
|
||||
"left"
|
||||
)
|
||||
.join(
|
||||
toTable,
|
||||
function () {
|
||||
})
|
||||
.leftJoin(toTable, function () {
|
||||
for (let relationship of relationships) {
|
||||
const toPrimary = relationship.toPrimary
|
||||
const to = relationship.to
|
||||
// @ts-ignore
|
||||
this.orOn(`${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
||||
}
|
||||
},
|
||||
"left"
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
return query.limit(BASE_LIMIT)
|
||||
|
|
Loading…
Reference in New Issue