Relation join conditions

Hey - let's say I have the following SQL:
SELECT
blocks.id,
blocks.type
FROM
inspections i
INNER JOIN inspection_blocks blocks ON i.id = blocks.inspection_id AND blocks.type = 'group';
SELECT
blocks.id,
blocks.type
FROM
inspections i
INNER JOIN inspection_blocks blocks ON i.id = blocks.inspection_id AND blocks.type = 'group';
Is there any way right now to specify the join condition of the relation, e.g?
export const inspectionRelations = relations(({many}) => ({
groups: many(blocks, {
where(fields, ops) {
return ops.eq(fields.type, 'group')
}
})
}))
export const inspectionRelations = relations(({many}) => ({
groups: many(blocks, {
where(fields, ops) {
return ops.eq(fields.type, 'group')
}
})
}))
2 Replies
Sillvva
Sillvva9mo ago
No, join conditions only matter at query time. The relation config expects only 3 properties: fields, references, and relationName. relationName is only important if distinguishing multiple relations between the same tables. https://orm.drizzle.team/docs/rqb#declaring-relations
Drizzle ORM - Query
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
erikshestopal
erikshestopalOP9mo ago
No, join conditions only matter at query time
I don't think that's accurate - in my example, the AND clause is part of the INNER JOIN statement and since drizzle's query interface constructs the joins on the developer's behalf, there's no way to specify the join condition.
Want results from more Discord servers?
Add your server