-
-
Notifications
You must be signed in to change notification settings - Fork 104
Nested relations not exposed in a polymorphic relation #1994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi @simoami , thanks for filing this! It seems to be pure typing issue. If you make a cast to "any", both attempt 1 and 2 should work at runtime. I'll see how to fix the typing problem. |
Fixed in 2.13.0 |
@ymc9 Thanks for the fix. I just tried 2.13.0. But seeing issues now. await db.user.update({
where: { id: 1 },
data: {
orgMemberships: {
create: [
{
organizationId: 1,
roleId: 1,
}
]
}
}) worked in 2.12.1 for both PrismaClient and EnhancedPrismaClient.
I followed the suggestion as it seems it only works with the full objects. I updated the fragment above to: await db.user.update({
where: { id: 1 },
data: {
orgMemberships: {
create: [
{
role: { connect: { id: 1 } },
organization: { connect: { id: 1 } },
}
]
}
}) Now another error says it wants the
This version works but typescript shouts the await db.user.update({
where: { id: user?.id },
data: {
orgMemberships: {
create: [
{
user: { connect: { id: 1} },
role: { connect: { id: 1 } },
organization: { connect: { id: 1 } },
},
],
},
},
}) |
Hi @simoami , could you show me your User model? |
Actually probably the full ZModel would be the best. Thanks! |
Description and expected behavior
Suppose you have an m-to-n relation:
OrganizationRole
<-OrganizationRolePrivilege
->Privilege
. The Organization role is a delegate further breaking down into 2 concrete models:SystemDefinedRole
andCustomOrganizationRole
:With the
Privilege
table is already preloaded with all privileges, it's not possible to create a new concrete Role and connect it to existing privileges.Below are a few attempts but unsuccessful:
Attempt 1: Connecting by foreign key
Attempt 2: Connecting by a relation name
Environment (please complete the following information):
Additional context
See related Discord thread.
With raw Prisma, this is achievable in 2 different ways. Both of which expose the
privilege
relation to connect to:The text was updated successfully, but these errors were encountered: