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
7f7bd8f447
commit
7109b34ea3
2 changed files with 29 additions and 41 deletions
|
@ -541,7 +541,7 @@ module External {
|
||||||
if (!linkTable || !linkPrimary) {
|
if (!linkTable || !linkPrimary) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const rows = related[key].rows || []
|
const rows = related[key]?.rows || []
|
||||||
const found = rows.find(
|
const found = rows.find(
|
||||||
(row: { [key: string]: any }) =>
|
(row: { [key: string]: any }) =>
|
||||||
row[linkPrimary] === relationship.id ||
|
row[linkPrimary] === relationship.id ||
|
||||||
|
|
|
@ -210,49 +210,37 @@ class InternalBuilder {
|
||||||
const { toTable, throughTable } = JSON.parse(key)
|
const { toTable, throughTable } = JSON.parse(key)
|
||||||
if (!throughTable) {
|
if (!throughTable) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
query = query.join(
|
query = query.leftJoin(toTable, function () {
|
||||||
toTable,
|
for (let relationship of relationships) {
|
||||||
function () {
|
const from = relationship.from,
|
||||||
for (let relationship of relationships) {
|
to = relationship.to
|
||||||
const from = relationship.from,
|
// @ts-ignore
|
||||||
to = relationship.to
|
this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
|
||||||
// @ts-ignore
|
}
|
||||||
this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
|
})
|
||||||
}
|
|
||||||
},
|
|
||||||
"left"
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
query = query
|
query = query
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
.join(
|
.leftJoin(throughTable, function () {
|
||||||
throughTable,
|
for (let relationship of relationships) {
|
||||||
function () {
|
const fromPrimary = relationship.fromPrimary
|
||||||
for (let relationship of relationships) {
|
const from = relationship.from
|
||||||
const fromPrimary = relationship.fromPrimary
|
// @ts-ignore
|
||||||
const from = relationship.from
|
this.orOn(
|
||||||
// @ts-ignore
|
`${fromTable}.${fromPrimary}`,
|
||||||
this.orOn(
|
"=",
|
||||||
`${fromTable}.${fromPrimary}`,
|
`${throughTable}.${from}`
|
||||||
"=",
|
)
|
||||||
`${throughTable}.${from}`
|
}
|
||||||
)
|
})
|
||||||
}
|
.leftJoin(toTable, function () {
|
||||||
},
|
for (let relationship of relationships) {
|
||||||
"left"
|
const toPrimary = relationship.toPrimary
|
||||||
)
|
const to = relationship.to
|
||||||
.join(
|
// @ts-ignore
|
||||||
toTable,
|
this.orOn(`${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
||||||
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)
|
return query.limit(BASE_LIMIT)
|
||||||
|
|
Loading…
Reference in a new issue