Reverse Edge not working

My reverse edge is not working although I have been doing everything write this is my type

type Brand{
        name
        bvid
        subBrands
    }
    type SubBrand{
        name
        bvid
        marketingMessage
        <~brand>
    }

And this how define its indices for reverse edge

subBrands: [uid] .
brand: uid @reverse .

after mutating it like this mutating nquad: <0x9> <subBrands> <0x7>

I am unable to get my brand in subbrand through reverse edge although it’s coming directly

working:

	brands(func:type(Brand)){
    name dgraph.type
    subBrands{
      name
    }
  }

Not working

subBrands(func:type(SubBrand)){
    		dgraph.type 
        name
        marketingMessage
          ~brand{
            name
          }
    }

I think you miss understood the reverse directive. You can’t set any reverse predicate as it was a custom thing, reverse edges just work on the same edge. By looking at your types, I can see that the only relationship you have between the Brand and the SubBrand is via subBrands and not brand. So in that case you should use like:

subBrands(func:type(SubBrand)){
    		dgraph.type 
        name
        marketingMessage
          <~SubBrand> {
            name
          }
    }

Also, you can use Alias

subBrands(func:type(SubBrand)){
    		dgraph.type 
        name
        marketingMessage
         brand : <~SubBrand> {
            name
          }
    }

Cheers.

So you I need to define my types like this?

type Brand{
        name
        bvid
        subBrands
    }
    type SubBrand{
        name
        bvid
        marketingMessage
        <~subBrands>
    }

it is not mandatory to define reverse edges.

1 Like

Thanks