Add conditions on relationships

Is it possible to add conditions when declaring relationships? In my example, I have books that have many resources. And one of those resources might be marked as the 'cover' of the book. I already have resources defined as a many relationship, but I want to add an additional one relationship for the cover resource, with an extra condition of isCover:true. e.g. something like this:
export const booksRelations = relations(books, ({ many, one }) => ({
chapters: many(chapters),
resources: many(resources),
coverResource: one(resources, {
fields: [books.id],
references: [resources.bookId],
where: eq(resources.isCover, true),, // not supported
}),
}));
export const booksRelations = relations(books, ({ many, one }) => ({
chapters: many(chapters),
resources: many(resources),
coverResource: one(resources, {
fields: [books.id],
references: [resources.bookId],
where: eq(resources.isCover, true),, // not supported
}),
}));
but it's not supported as far as I can tell, and I don't see anything mentioned about adding extra conditions to relationships in the docs.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server