Skip to content

Commit

Permalink
chore(db-postgres): fix nested join query
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed May 26, 2024
1 parent 231c69b commit 2a8f144
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/db-postgres/src/queries/getTableColumnFromPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,10 @@ export const getTableColumnFromPath = ({
tableName: newTableName,
value,
})
} else if (pathSegments.length > 1) {
} else if (
pathSegments.length > 1 &&
!(pathSegments.length === 2 && pathSegments[1] === 'id')
) {
// simple relationships
const columnName = `${columnPrefix}${field.name}`
const newTableName = adapter.tableNameMap.get(
Expand Down Expand Up @@ -575,7 +578,10 @@ export const getTableColumnFromPath = ({
})
} else {
joinAliases.push({
condition: and(eq(newAliasTable.id, adapter.tables[tableName][columnName])),
condition: eq(
newAliasTable.id,
aliasTable ? aliasTable[columnName] : adapter.tables[tableName][columnName],
),
table: newAliasTable,
})
}
Expand All @@ -595,14 +601,6 @@ export const getTableColumnFromPath = ({
tableName: newTableName,
value,
})
} else {
// simple relationship on id
return {
columnName: `${columnPrefix}${field.name}`,
constraints,
field,
table: adapter.tables[tableName],
}
}
break
}
Expand Down

0 comments on commit 2a8f144

Please sign in to comment.