[ask] Add arbitrary `ON` conditions for `relations`
I'm trying to create a relation definition for a model, but it's not just a map between a reference ID, but I want to add more conditions to the ON clause. Is it possible to define more conditions for relations?
Example:
SELECT a.name, b.value
FROM table_a a
JOIN table_b b ON a.b_id = b.id AND b.type = 'primary'
How do I add b.type === 'primary' without going down the rabbit hole of building my own query?
Currently this isn't supported, but it's quite essential feature and I'll try to add it soon.
To have:
relations = {
things: this.hasMany(() => Thing, {
columns: ['id'],
references: ['thingId'],
where: {
type: 'primary',
},
})
}
And it should not just be added to ON, but also added when creating a sub-record.
Thanks, for now I figured I can add conditions in the query itself, on the relational select statement.
Ready! the new on option
This is great 👍 thanks @romeerez