Filtering by relation


I want to get all nodes who have the same project uid

my query is like that

Blockquote

query {
q(func: has(evt_name)) @filter(uid_in(~project_uid, “0xe23”)) {
uid
project_uid {
uid
}
}
}

but I get no result


in the other hand my data :

Report a Dgraph Bug

What version of Dgraph are you using?

Dgraph Version
$ dgraph version
 
PASTE YOUR RESULTS HERE

Have you tried reproducing the issue with the latest release?

What is the hardware spec (RAM, OS)?

Steps to reproduce the issue (command/config used to run Dgraph).

Expected behaviour and actual result.


Experience Report for Feature Request

Note: Feature requests are judged based on user experience and modeled on Go Experience Reports. These reports should focus on the problems: they should not focus on and need not propose solutions.

What you wanted to do

What you actually did

Why that wasn’t great, with examples

Any external references to support your case

1 Like

Use cascade instead:

query {
q(func: has(evt_name)) @cascade  {
  uid
  project_uid @filter(uid(0xe29)) {
    uid
  }
 }
}
1 Like

thank you for your response but doesn’t working for me

Please show me the result without filter on project_uid

the problem was that uid is 0xe230 not 0xe23 but still get the result of project uid that are 0xe230

You missed @cascade

1 Like

it working thank you

1 Like

Your original filter was looking at the reverse project_uid edge: ~project_uid

The following may also work:

query {
    q(func: has(evt_name)) 
    @filter(uid_in(project_uid, “0xe23”))
    {
        uid
        project_uid {
            uid
        }
    }
}

If you want to use a variable when locating your projects UID, then you can do something like this:

query {
    proj as var(func: eq(project.name, “foo”)
    q(func: has(evt_name)) 
    @filter(uid_in(project_uid, uid(proj)))
    {
        uid
        project_uid {
            uid
        }
    }
}

Note: @cascade also works but may not be the most optimal (assuming performance is of concern). This is because @cascade is applied after the query: Cascade Directive - Query language