I am stuck in preparing query to fetch based on relation. I have a schema like this.
title: string @index(exact) .
actions: [uid] @reverse .
phase: string @index(exact) .
created_at: datetime .
type Job {
title
actions
}
type Action {
phase
created_at
}
Data like this (may not be syntactically correct, just for idea):
{
"set": [
{
"title": "Job 001",
"dgraph.type": "Job",
"actions": [
{
"phase": "review",
"created_at": "2020-04-20T09:30:00Z",
"dgraph.type": "Action"
},
{
"phase": "research",
"created_at": "2020-04-22T06:00:00Z",
"dgraph.type": "Action"
},
{
"phase": "confirm",
"created_at": "2020-04-25T10:20:00Z",
"dgraph.type": "Action"
},
]
}
]
}
As you can see, a Job has different actions review
, research
and confirm
(in this order). I am trying to get the jobs that are in research
phase. I think I need to order the actions on created_at
with desc
, check the first one and get the according jobs. But how would I do it in the query? Or is this possible to do it in a single query? Any idea will be really helpful.
Thanks