kids-parents relation - is it possible?

I'm trying to setup relations between kids and parents. kids has father_id and mother_id columns that reference the parents.id. So far I have:
const parentsRelations = relations(parents, ({ many }) => ({ kids: many(kids) }));

const kidsRelations = relations(kids, ({ one }) => ({
father: one(parents, {
fields: [kids.father_id],
references: [parents.id],
relationName: 'father'
}),
mother: one(parents, {
fields: [kids.mother_id],
references: [parents.id],
relationName: 'mother'
})
}));
const parentsRelations = relations(parents, ({ many }) => ({ kids: many(kids) }));

const kidsRelations = relations(kids, ({ one }) => ({
father: one(parents, {
fields: [kids.father_id],
references: [parents.id],
relationName: 'father'
}),
mother: one(parents, {
fields: [kids.mother_id],
references: [parents.id],
relationName: 'mother'
})
}));
I'm trying to figure out if I can make it work with this setup, with having parents.kids have all kids as reverse-referenced by both father_id and mother_id ?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?