Possible bug with nested query + reverse access

I have a pretty nested query.
// fails
const result = await tx.query.projectinternalcost.findMany({
with: {
projectinternalcostitem: {
with: {
projecttransactionitems: {
with: {
projecttransaction: true //<- reverse many-to-one relation
}
},
itemcategory: true
},
}
});
// fails
const result = await tx.query.projectinternalcost.findMany({
with: {
projectinternalcostitem: {
with: {
projecttransactionitems: {
with: {
projecttransaction: true //<- reverse many-to-one relation
}
},
itemcategory: true
},
}
});
It results in this error:
[0] code: '42703',
[0] detail: 'There is a column named "projecttransaction_id" in table "project_projectinternalcosts_projectinternalcostitems_projecttr", but it cannot be referenced from this part of the query.',
[0] hint: 'To reference that column, you must mark this subquery with LATERAL.',
[0] code: '42703',
[0] detail: 'There is a column named "projecttransaction_id" in table "project_projectinternalcosts_projectinternalcostitems_projecttr", but it cannot be referenced from this part of the query.',
[0] hint: 'To reference that column, you must mark this subquery with LATERAL.',
I can make the query work if i go one level down:
// works
const result = await tx.query.projectinternalcostitem.findMany({
with: {
projecttransactionitems: {
with: {
projecttransaction: true
}
},
itemcategory: true
}
});
// works
const result = await tx.query.projectinternalcostitem.findMany({
with: {
projecttransactionitems: {
with: {
projecttransaction: true
}
},
itemcategory: true
}
});
Or alternatively if i remove the reverse access:
// works
const result = await tx.query.projectinternalcost.findMany({
with: {
projectinternalcostitem: {
with: {
projecttransactionitems: true,
itemcategory: true
},
}
});
// works
const result = await tx.query.projectinternalcost.findMany({
with: {
projectinternalcostitem: {
with: {
projecttransactionitems: true,
itemcategory: true
},
}
});
Hope you guys can assist me with this!
2 Replies
dion
dionOP5mo ago
For more context, i have uploaded a summary of the schema and relationship
dion
dionOP5mo ago
JIC someone faces the same issue, this is a table length issue: https://github.com/drizzle-team/drizzle-orm/issues/2066
GitHub
[BUG]: Deeply nested queries fail due to table name length · Issue ...
What version of drizzle-orm are you using? 0.30.1 What version of drizzle-kit are you using? 0.20.14 Describe the Bug When creating a query with deeply nested data, the sql generated uses names bas...
Want results from more Discord servers?
Add your server