Dgraph: List of uid [uid]

Created on 11 Mar 2019  路  6Comments  路  Source: dgraph-io/dgraph

I am wondering why we cant have a list of [uid] in the schema?

I have a node which "owns" multiple nodes.

kinquestion

Most helpful comment

Before 1.1 (still not released) setting a schema to uid means that there might be multiple edges of type predicate coming out of a node. This seems to be the behavior you need so you don't need to make any changes to your schema as that's the default behavior.

However, in versions less than 1.1 there is no way to enforce that at most there will be a single edge of a given predicate coming out of a node (This is possible to do for other data types, e.g string and [string] have different meanings). This is fixed in 1.1 so once that release is out both uid and [uid] will be supported.

All 6 comments

We gonna have it in v1.1 release https://github.com/dgraph-io/dgraph/pull/2895

Today all uid edges are multiple.

What does edges are multiple mean? How can I achieve [uid] now?

Before 1.1 (still not released) setting a schema to uid means that there might be multiple edges of type predicate coming out of a node. This seems to be the behavior you need so you don't need to make any changes to your schema as that's the default behavior.

However, in versions less than 1.1 there is no way to enforce that at most there will be a single edge of a given predicate coming out of a node (This is possible to do for other data types, e.g string and [string] have different meanings). This is fixed in 1.1 so once that release is out both uid and [uid] will be supported.

Thanks martinmr,

I was writing. Martin explains better. But my explanation is different However it's the same.

"uid" Type in schema means a "node to N nodes" relation. Today the UID is one to many and Nodes can be many to many. Now you already has [uid] by default (one to many). But it's not typed as "[uid]" in the schema itself.

Maybe you're confusing the UID Type. Can you explain better what you wanna really achieve? And you can't now.

Not @martinmr but I need multiple uid since in my model, a Stuff can have multiple Tags. If I put Tags as [string], when a user has millions of Stuff and suddenly wants to rename a Tag, they need to update Stuff set tag = newName where tag = oldName (sorry for SQL pseudo-code). Ideally, it should be update Tag set name = newName where tagId = someTagIdReferencedByStuff.

EDIT: Also, the Tags should obviously be namespaced to the user, otherwise when user A renames "foo" to "bar", everyone else suddenly has their "foo" Tag renamed to "bar".

Or, could I achieve this better with different approach?

Use the delete operation https://docs.dgraph.io/mutations/#delete. When you specify the object and a list scalar predicate, this will delete only that value and leave the rest intact. After that, you can add the updated tag value. Basically there's no explicit update operation in Dgraph but you can simulate it by doing a delete and an add.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

protheusfr picture protheusfr  路  4Comments

yupengfei picture yupengfei  路  4Comments

djdoeslinux picture djdoeslinux  路  4Comments

bytefish picture bytefish  路  4Comments

pjebs picture pjebs  路  4Comments