Giter Site home page Giter Site logo

Comments (14)

sedubois avatar sedubois commented on April 30, 2024 1

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.

marktani avatar marktani commented on April 30, 2024 1

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.

kbrandwijk avatar kbrandwijk commented on April 30, 2024 1

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.

sorenbs avatar sorenbs commented on April 30, 2024

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.

schickling avatar schickling commented on April 30, 2024

That being said, we should probably provide a more powerful solution to create multi-field/multi-model constraints.

from prisma1.

sedubois avatar sedubois commented on April 30, 2024

Would you have news on this?

from prisma1.

sedubois avatar sedubois commented on April 30, 2024

It's actually still annoying, now the field selector looks like this: 😅

    slug {
      slug
    }

from prisma1.

marktani avatar marktani commented on April 30, 2024

That's why I'd suggest naming the field something like key, title, name.

from prisma1.

sedubois avatar sedubois commented on April 30, 2024

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.

marktani avatar marktani commented on April 30, 2024

I suggest waiting for #23 and then checking the unicity when creating and updating users or organizations.

from prisma1.

sedubois avatar sedubois commented on April 30, 2024

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.

marktani avatar marktani commented on April 30, 2024

See #65 and #90.

from prisma1.

kbrandwijk avatar kbrandwijk commented on April 30, 2024

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.

sorenbs avatar sorenbs commented on April 30, 2024

Please see proposed spec in https://github.com/graphcool/framework/issues/1300

from prisma1.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.