Comments (14)
Agreed with both comments, the stated workarounds is OK for now, it's just not very clean and maintainable. Something more intuitive would be very appreciated.
from prisma1.
In this case, adding a Slug
model with a unique key: String!
field is the way to go. User
and Org
will have a one-to-one relation to Slug
.
from prisma1.
Unicity across different models could be solved using a scope parameter for @isUnique, and a @scope directive on Types, so you have some kind of 'grouping' for this kind of functionality.
from prisma1.
One approach that might or might not work based on your use case is to create a separate Slug model with a unique slug field. Then you can either reference this from the User and Org models or simply use it as a "slug generator" that simply verifies that a slug is unique before you assign it to a new User or Org.
Would either of these solutions work for you?
from prisma1.
That being said, we should probably provide a more powerful solution to create multi-field/multi-model constraints.
from prisma1.
Would you have news on this?
from prisma1.
It's actually still annoying, now the field selector looks like this: 😅
slug {
slug
}
from prisma1.
That's why I'd suggest naming the field something like key
, title
, name
.
from prisma1.
OK, next question is that now I lose the ability to select a User(slug: $slug)
, because I cannot add a unique constraint on the relation. How do I work around that?
from prisma1.
I suggest waiting for #23 and then checking the unicity when creating and updating users or organizations.
from prisma1.
Actually, couldn't you instrument the code to mark the linked field as unique? After all, it is unique in the linked model. That sounds simple enough and would answer the issue I think?
from prisma1.
from prisma1.
Or maybe when interfaces are implemented, and you specify a isUnique directive on an interface field, that field will be unique across all Types that implement the interface.
from prisma1.
Please see proposed spec in https://github.com/graphcool/framework/issues/1300
from prisma1.
Related Issues (20)
- Self-relation column order? HOT 1
- Prisma1 with Apple M1 HOT 7
- Mutations with disconnect=true on an relation that is not connected to anything fails with an error HOT 1
- Circular dependency while mocking the Prisma client using both approach singelton and context
- host.docker.internal not working on prismagraphql/prisma:1.34 on docker-compose (1.29.2) docker 20.10.9 CentOS 8.4.2105 HOT 1
- Intermittent P1001 - "Can't reach database server..." HOT 1
- `updatedAt` field not changing after running a connect operation via the update mutation HOT 1
- Prisma 1.34 documentation errors HOT 1
- Invalid Issue Documentation link HOT 1
- log4j - CVE-2021-4428 HOT 2
- The type of `where` part of `delete` function is wrong when using `@@unique`
- Prisma 1 Cloud was sunset on September 1st, 2022 HOT 3
- Error prisma1 deploy HOT 1
- Cascade delete not set on one-to-many relation HOT 1
- prisma1 introspect does not return anything
- updatedFields always returns an empty array HOT 1
- Prisma1 deploy throws 504 Gateway Time-out randomly HOT 2
- "Join" where result would have been a big data set throws an error (performance) HOT 1
- Issues adding or modifying records in Admin
- Prisma 1 was deprecated on Sept, 1st 2022 — Upgrade to the latest version of Prisma
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prisma1.