-
Notifications
You must be signed in to change notification settings - Fork 867
Unicity across different models #24
Comments
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? |
That being said, we should probably provide a more powerful solution to create multi-field/multi-model constraints. |
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. |
Would you have news on this? |
In this case, adding a |
It's actually still annoying, now the field selector looks like this: 😅
|
That's why I'd suggest naming the field something like |
OK, next question is that now I lose the ability to select a |
I suggest waiting for #23 and then checking the unicity when creating and updating users or organizations. |
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? |
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. |
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. |
Please see proposed spec in https://github.com/graphcool/framework/issues/1300 |
I want to create two models,
User
andOrg
which both have aslug
, ensuring that this slug is unique across all users and orgs (similar to GitHub and such sites). I don't think graph.cool currently allows this?The text was updated successfully, but these errors were encountered: