Relation query `extras` needs access to `with`

I have a mysql table with two relations to another table. (one is for source values, one is for optional admin edited values.) The app logic is "if admin value exists, return admin value, else return source value". (But do not return both, since it would be a large network payload) The relation query easily includes the 2 related columns via with key. But, the extras key cannot access the related columns. Is there another way to achieve this "computed" extras column type? (Maybe this is a good use for "Views" feature) e.g.:
db.query.table.findMany({
with: {
relation1: true,
relation2: true, // optional
},
extras: {
relationComputed: table.relation2 ?? table.relation1,
},
})
db.query.table.findMany({
with: {
relation1: true,
relation2: true, // optional
},
extras: {
relationComputed: table.relation2 ?? table.relation1,
},
})
1 Reply
mcgrealife
mcgrealife16mo ago
Maybe this is what the docs are mentioning:
As of now aggregations are not supported in extras, please use core queries for that
https://orm.drizzle.team/docs/rqb#include-custom-fields which is no problem, because I am discovering the sql operator really is magic! 👍
Want results from more Discord servers?
Add your server