cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple relationships of same label between two nodes best practices

geronimo4j
Graph Buddy

Hi I have a bunch of questions I hope you don't mind!

I have Users, Lists, and Movies.
Where a User could create Lists which consist of Movies.

Lists are interesting because you can add Movies, but you can also track how many times you've seen them.

So I was thinking i would model it like this:

(User) -[HAS_LIST]->(List)-[HAS_MOVIE]-(Movie)

And then for each HAS_MOVIE relationship I would add a property date_added.

My question is: does it make sense/does it go against best practices to have multiple relationships of the same Label between the same two nodes? Is it fine to do this and have unique properties for each?

Essentially, I would then try to just call all distinct movies for the list, and then if possible see if I could list out all HAS_MOVIE dates? Would it be possible to fetch for all of those date_added in graphql, and retrieve that as a list?

Thank you in advance!

Edit: I tried this and it appears to overwrite the existing node. How else might you store the list of dates where a Movie was added to a List - like if a user wanted to keep track of their watching habits?

Additionally, it doesn't appear like I can request all Movies for playlists, and instead have to go in a roundabout way of getting the date_added as a separate result from the node:

{
  lists{
    moviesConnection {
      edges {
        date_added
        node {
          id
          name
        }
      }
    }
  }
}

which yields:

    "lists": [
      {
        "moviesConnection": {
          "edges": [
            {
              "date_added": "2021-11-13T04:00:16.943Z",
              "node": {
                "id": "10420d24-8056-442c-99e2-79935c0769cd",
                "name": "Transformers: The Last Knight"
              }
            }
          ]
        }
     }
   ]
}

rather than something like:

{
    lists: [
        movies [{
            id
            name
            date_added: ["11/12/2021", "11/06/2021", "11/02/2021"]
        }]
    ]
}
1 REPLY 1

In principle it's not a problem but I don't know how well it is supported in the graphql library, esp. when creating/merging the relationships.

/cc @danstarns