Search code examples
graphqlgraphcool

Multiple relation between two models


I have two databases/models User and Listing.

I am trying to create two relations:

  • One User to one Listing called "ListingOwner"
  • One User to many Listing called "ListingCreator"

My users can create multiple listings. I want to keep that as "Creator". But any user is allowed to come in and "claim" a listing, making them the "Owner". However in graph.cool I can't create more then one relationshp between User and Listing model, it gives me this error:

https://i.sstatic.net/r8elX.png

Server request for mutation AddRelationMutation failed for the following reasons: 1. A field with the name 'listing' already exists AddRelationInput!) {addRelation(input:$input_0) {clientMutat ^^^


Solution

  • A model can only have one field with a given name. In your case the solution would be to rename one of the listing fields to something else. When you create the relation you can change the field name in the ui as below:

    enter image description here

    Hope that helps :-)