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

**URL:** <https://discuss.dgraph.io/t/if-you-have-a-two-way-relationship-between-2-types-does-it-matter-which-node-you-put-the-hasinverse-index-in/9724>\
**Category:** GraphQL\
**Tags:** graphql, kind:question, help-wanted\
**Created:** [August 28, 2020, 5:47am UTC](https://discuss.dgraph.io/t/if-you-have-a-two-way-relationship-between-2-types-does-it-matter-which-node-you-put-the-hasinverse-index-in/9724 "2020-08-28T05:47:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorillastanley](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gorillastanley/32/4518_2.png) [@gorillastanley](https://discuss.dgraph.io/u/gorillastanley)\
**Post date:** [August 28, 2020, 5:47am UTC](https://discuss.dgraph.io/t/if-you-have-a-two-way-relationship-between-2-types-does-it-matter-which-node-you-put-the-hasinverse-index-in/9724/1 "2020-08-28T05:47:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![amaster507](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/amaster507/32/4123_2.png) [@amaster507](https://discuss.dgraph.io/u/amaster507)\
**Post date:** [August 28, 2020, 6:02am UTC](https://discuss.dgraph.io/t/if-you-have-a-two-way-relationship-between-2-types-does-it-matter-which-node-you-put-the-hasinverse-index-in/9724/2 "2020-08-28T06:02:18Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![gorillastanley](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/gorillastanley/32/4518_2.png) [@gorillastanley](https://discuss.dgraph.io/u/gorillastanley)\
**Post date:** [August 28, 2020, 6:05am UTC](https://discuss.dgraph.io/t/if-you-have-a-two-way-relationship-between-2-types-does-it-matter-which-node-you-put-the-hasinverse-index-in/9724/3 "2020-08-28T06:05:33Z")

</div>

I saw this message in another post:

> [@Ref to a node without an ID](http://discuss.hypermode.com/t/ref-to-a-node-without-an-id/9717/6):
>
> As @amaster507 said, not possible. Yup. P.S. attributes: [Attribute] @hasInverse(field: belongsTo) is wrong. hasInverse needs to be on belongsTo: Entity! @hasInverse(field: attributes)

I’m guessing it’s wrong then?
