Getting seemingly incorrect relation error

export const productSetRelations = relations(productSets, ({ many, one }) => ({
parentProductSetTemplate: one(productSetTemplates, {
fields: [productSets.parentProductSetTemplateId],
references: [productSetTemplates.id],
relationName: 'parentProductSetTemplate'
}),
productSetTemplate: one(productSetTemplates, {
fields: [productSets.productSetTemplateId],
references: [productSetTemplates.id]
})
}));

export const productSetTemplateRelations = relations(productSetTemplates, ({ many, one }) => ({
productSet: one(productSets),
prototypeProductSets: many(productSets, { relationName: 'parentProductSetTemplate' }),
}));
export const productSetRelations = relations(productSets, ({ many, one }) => ({
parentProductSetTemplate: one(productSetTemplates, {
fields: [productSets.parentProductSetTemplateId],
references: [productSetTemplates.id],
relationName: 'parentProductSetTemplate'
}),
productSetTemplate: one(productSetTemplates, {
fields: [productSets.productSetTemplateId],
references: [productSetTemplates.id]
})
}));

export const productSetTemplateRelations = relations(productSetTemplates, ({ many, one }) => ({
productSet: one(productSets),
prototypeProductSets: many(productSets, { relationName: 'parentProductSetTemplate' }),
}));
Error: There are multiple relations between "productSets" and "ProductSetTemplate". Please specify relation name
Error: There are multiple relations between "productSets" and "ProductSetTemplate". Please specify relation name
Shouldnt this be sufficient for relation names? If not, i dont see how i could even add one? my schema was working with prisma so i dont think i need to add another FK
4 Replies
Angelelz
Angelelz9mo ago
I guess it should be enough to only add one relationName the way you have it I think that drizzle just shorcuts to an error as soon as it sees several relatiions with a lower number of relation names You can just add the relation name to the other relation just to satisfy drizzle
jakeleventhal
jakeleventhal9mo ago
how would i do that without an additional foreign key productSet: one(productSets) in order to add a relation name i also need fields and references
Angelelz
Angelelz9mo ago
productSet: one(productSets, {
references: [productSets.productSetTemplateId],
fields: [productSetTemplates.id],
relationName: "myRelationName"
}),
productSet: one(productSets, {
references: [productSets.productSetTemplateId],
fields: [productSetTemplates.id],
relationName: "myRelationName"
}),
Just the opposite to the other side of the relation? I not completely sure, but it seems to me that that should work
jakeleventhal
jakeleventhal9mo ago
yeah that should work actually ty
Want results from more Discord servers?
Add your server