Skip to content

Incomplete Support for Explicit Many-to-Many Relations #40

@inspire-man

Description

@inspire-man

Problem Description
Prismabox's current implementation doesn't fully support Prisma's explicit many-to-many relations in generated types, specifically:

​​Create operations​​ lack support for nested create/connect operations through join tables
​​Where conditions​​ don't support nested filtering through join table relationships
Current Limitations

  1. Create Input Limitations
    The generated ArticleRelationsInputCreate only supports basic connect operations:Problem Description
    Prismabox's current implementation doesn't fully support Prisma's explicit many-to-many relations in generated types, specifically:

​​Create operations​​ lack support for nested create/connect operations through join tables
​​Where conditions​​ don't support nested filtering through join table relationships
Current Limitations

  1. Create Input Limitations
    The generated ArticleRelationsInputCreate only supports basic connect operations:
tags: t.Optional(
  t.Object({
    connect: t.Array(t.Object({ id: t.String() }))
  })
)

But Prisma supports richer operations like:

tags: {
  create: [{
    assignedBy: 'Bob',
    assignedAt: new Date(),
    tag: { create: { name: 'New Tag' } }
  }],
  connectOrCreate: [{
    where: { id: 'tag1' },
    create: { 
      assignedBy: 'Alice',
      assignedAt: new Date(),
      tag: { connect: { id: 'tag1' } }
    }
  }]
}
  1. Where Filter Limitations
    The generated ArticleWhere type doesn't support nested filtering through join tables:
// Missing support for:
where: {
  tags: {
    some: {
      tag: {
        name: 'Technology'
      }
    }
  }
}

Expected Behavior
Prismabox should generate types that fully support Prisma's explicit many-to-many capabilities:

For Create Operations

tags: t.Optional(
  t.Object({
    create: t.Array(
      t.Object({
        assignedBy: t.String(),
        assignedAt: t.Date(),
        tag: t.Object({
          create: t.Object({...}),
          connect: t.Object({ id: t.String() }),
          connectOrCreate: t.Object({...})
        })
      })
    ),
    connect: t.Array(t.Object({ id: t.String() })),
    connectOrCreate: t.Array(...),
    // Other operations...
  })
)

For Where Conditions

export const ArticleWhere = t.Partial(
  t.Recursive(
    (Self) =>
      t.Object({
        // ...other fields...
        tags: t.Object({
          some: t.Object({
            tag: t.Object({
              id: t.String(),
              name: t.String(),
              // Other tag fields...
            })
          }),
          every: t.Object({...}),
          none: t.Object({...})
        })
      }),
    { $id: "Article" }
  )
)

Reproduction Steps
1.Define models with explicit many-to-many relations:

model Article {
  tags TagsOnArticles[]
}

model Tag {
  articles TagsOnArticles[]
}

model TagsOnArticles {
  article Article
  tag Tag
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions