Skip to content

No relation tables generated when using views in many-to-many relations #26593

@ptrxyz

Description

@ptrxyz

If a view (preview feature) is part of a many-to-many relation, no relation tables are generated.
Let's assume this example:

I have a view "DepartmentInfo" as well as model "User". The user can be part of many departments and a department can have many users -- we are talking about n:m relation.

I defined the view as well as the model in my schema, but prisma doesn't seem to create the relation tables (_User_DepartmentInfo) for that relation. As soon as I change the view to a model, the table is generated.

I have no idea how Prisma is storing the relations or if I am doing it wrong, but this is my observation and i think this is not intended.

// this schema adds relation tables
model User {
    id Int @id
    departments Department[]
}

model Department {
    id Int @id
    users User[]
}
// this schema DOES NOT add relation tables
model User {
    id Int @id
    departments Department[]
}

view Department {
    id Int @id
    users User[]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.topic: implicit m:nimplicit many-to-many relationstopic: m:nmany-to-many relationstopic: views

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions