If you have a two-way relationship between 2 types, does it matter which node you put the hasInverse index in?

If you have a two-way relationship between 2 types, does it matter which node you put the hasInverse index in?
Not sure on which would be preferred, is there some general rule

eeni meeni miini moh

Seriously though, I do not think that it makes a hill of beans difference which side has it. Dgraph generates DQL (GraphQL±) “resolvers” from your GQL and it looks for these to add in the functionaility on both ends:

If (hasInverse link || opposite side hasInverse link) {
  onUpdate {
    update other end
  }
  onAdd {
    add other end
  }
  onDelete {
    delete other end
  }
}

The deeper you get into it, you will see that it does not work like the @reverse directive from DQL but rather actually creates two edges and manages both edges in the resolvers. If you start to do some data manipulation later on with DQL remember this. You could break things by removing half of a link, or not get the results expected because you only added half of the link. This is also important if you build a RDF file to use in a bulk loader. You will have to define both edges.

3 Likes

I saw this message in another post:

I’m guessing it’s wrong then?