# @reverse dircetive

**URL:** <https://discuss.dgraph.io/t/reverse-dircetive/11536>\
**Category:** Dgraph\
**Tags:** kind:question, area:querylang\
**Created:** [November 19, 2020, 11:06am UTC](https://discuss.dgraph.io/t/reverse-dircetive/11536 "2020-11-19T11:06:23Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [November 23, 2020, 4:39am UTC](https://discuss.dgraph.io/t/reverse-dircetive/11536/7 "2020-11-23T04:39:25Z")

</div>

Sorry for the delay.

> [@spinelsun](#):
>
> I wonder what I should do to create a bidirectional connection between some types.

If the direction doesn’t add new information about the relation. I would use a reverse index. Otherwise, I would create two edges that represent a concept. e.g: “if a user has an outgoing edge called `<askfriendship>` and an incoming edge `<acceptedfriendship>` - so this user has a friend”.

I personally use reverse edges just to traverse. Applying complex filtering.

> [@spinelsun](#):
>
> I need to have the ability to query a membership and find its owner

Well, if you have a deep relation, traversing with the reverse directive is your tool.

> [@spinelsun](#):
>
> or to query a user and find all of its membership.

That’s a normal traversing through the nested graph.

> [@spinelsun](#):
>
> What I don’t know is how to do this in dql.

### Normal direction

```auto
{
  var(func: eq(User.username, "Lucas")){
    User.memberships {
     REPOS as Membership.in_repository
    }
  } 
  q(func: uid(REPOS)){
    Name : Repository.name
  }
}

```

### Reverse direction

```auto
{
  var(func: eq(Repository.name, "Something")){
    <~Membership.in_repository> {
     User as <~User.memberships>
    }
  } 
  q(func: uid(User)){
    Name : User.username
  }
}

```

Both `<Membership.in_repository>` and `<User.memberships>` have to have the reverse directive in the schema.

---

_[View the full topic](https://discuss.dgraph.io/t/reverse-dircetive/11536)._
