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
Scoped Many-to-many Relation #2881
Comments
I would consider this to be related to #678 as I would usually use a sql view to achieve this. Embedding a query in the schema is not ideal in my opinion. |
But then you have business logic living in two places: your code and the database. I'd prefer that the database just be a dumb store of data and let all the logic for that defines how my application works to be in the application code itself. |
Active Record provides a solid implementation of this.
AR specifies the business logic as a constraint on the association. When the association is queried, the conditional is appended. When the association is saved, the condition can be validated to ensure the This would be invaluable. |
I view this less as business logic and more as data integrity. Currently, if I define the concept of a It would be possible to save a text file in place of the logo using Prisma without guarding logic. If this were defined on the schema directly your schema becomes the source of truth for the data integrity. IMO the domain of concerns dictates that the database governs which data should pass into it's storage. The code should trust that the data being fed to it is structurally sound without needing to have external knowledge of how the data was previously processed. IE: The database should be tight and restrictive as possible to enforce data integrity. This should happens on the Prisma schema layer rather than the execution layer. Thus I believe this feature has merrit. |
It's a shame we don't have updates about this feature, it would be extremely useful! |
Problem
Given a many-to-many relationship, I would like to be able to define a relationship that scopes to a subset of records based on a value in the join table.
Say I have models User and Group. I also have a join table
GroupMembership
:The join table also has a
role
attribute. For our purposes say it can have a value ofadmin
ormember
. I want to create two different relations on theGroup
model which take these into account:Suggested solution
I would like a way to specify a relation that is limited to a subset of the joined items. For anyone who has used Ruby-on-Rails/ActiveRecord, this is the equivalent of passing "scope" argument to a
has_many through:
association. Something like this might work for the example above:The text was updated successfully, but these errors were encountered: