1
0
Fork 0
mirror of synced 2024-07-05 06:20:55 +12:00

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:
mike12345567 2022-02-11 14:04:23 +00:00
parent 580bb89fda
commit f77b596a07
2 changed files with 29 additions and 41 deletions

View file

@ -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 ||

View file

@ -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)