Reputation: 212
leftJoin only returns the first tables data but not the second table when I use the Knex leftJoin() method with an Objection.js model. The same query works fine when I do it directly in the terminal with psql
the query looks like this:
const result = await Table1Model.query()
.leftJoin(
'table_2',
'table_2.table_2_id',
'table_1.table_2_id'
)
.where('table_1_id', '=', table1Id);
I expect the result to include all of the table_2
columns where there is an id match with table_1
.
I am only getting columns for table_1
Upvotes: 0
Views: 722
Reputation: 4526
if you like to get columns only from table_2-
const result = await Table1Model.query()
.leftJoin(
'table_2',
'table_2.table_2_id',
'table_1.table_2_id'
)
.columns('table_2.*') // add columns
.where('table_1_id', '=', table1Id);
Upvotes: 3