As posted on the community forum:
It would be useful to be able to assign a uid to a predicate directly without adding it to a Posting List. For example, I might have a predicate teacher, where it is only ever possible to have one teacher at a time.
At the moment I would have to do the following to update the predicate, which means 2 round trips and is unnecessarily verbose.
mutation {
delete {
<0x4> teacher * .
}
}
mutation {
set {
<0x4> teacher <0x9> .
}
}
Ideally, you would want to be able to specify in the schema that that predicate only accepts a single uid.
mutation {
schema {
teacher: uid @unary
}
}
It would also have the added benefit of being able to return an object instead of an array when the unary predicate is being queried, as it would know there could only ever be one node/object.
Once we support transactions, this is something that users can handle at their end.
Related issue: https://github.com/dgraph-io/dgraph/issues/1445
Think I was too quick to declare that txns would solve this. It would still require two round trips to first delete the edges, and then set one. So, the idea of having a @unary in the schema is a good one.
If it's not too complex to implement, we'll do so (in v0.9 series).
Great news!
This will be really helpful, as there are a lot of instances where I want to reference a single node in a one-to-many relationship.
Just thinking about this a bit more.
This feature would also enable efficient lookup of a uid by predicate, as there would only ever be one uid for a given node/predicate, performing a search would essentially the same as a hash lookup.
You could then add a new index / filter for that as well.
Is this still on the cards?
This looks like a duplicate of #2511.
We're working on #2511 .
Most helpful comment
Great news!
This will be really helpful, as there are a lot of instances where I want to reference a single node in a one-to-many relationship.