[ask] How to reuse repo code in subquery
Closed this issue · 3 comments
bingtsingw commented
const data = db.xxx.select({
relationCount: q => q.relation.where(xxx).count() // the q in subquery can't re-use repo methods
})
romeerez commented
How about myRepo(q.relation).whereSomething(xxx)
?
export const myRepo = createRepo(db.relationTable, {
queryMethods: {
whereSomething: (xxx: SomeType) => {
return q.where(xxx);
},
},
});
const data = db.xxx.select({
relationCount: q => myRepo(q.relation).whereSomething(xxx).count() // the q in subquery can't re-use repo methods
})
bingtsingw commented
Thank you, romeerez, it works well, I didn't think it would work.
This technique should be written into docs.