Update one-to-many relationship

I have the schema

uuid: string @index(hash) .
owner: uid @reverse .

type Owner {
    uuid: string

type Device {
    uuid: string
    owner: Owner

The owner has many devices, the device has one owner

And the next data

_:foo <uuid> "foo" .
_:foo <dgraph.type> "Owner" .

_:bar <uuid> "bar" .
_:bar <dgraph.type> "Owner" .

_:baz <uuid> "baz" .
_:baz <dgraph.type> "Device" .
_:baz <owner> _:foo .

I want to change the device owner - from foo to bar, so I run the upsert

query {
  device as var(func: eq(uuid, "baz")
  owner as var(func: eq(uuid, "bar")

mutation {
  set {
    uid(device) <owner> uid(owner) .

The question is if it is right to make upsert in this way? Because after this upsert relation between baz-device and foo-owner still exists
Or should I delete old relation and only then add a new one?

Hi @poketulhu,

The mutation that you are doing is adding a new relation independent of the older relations. If you want to remove some relation then you should delete it as well.

Then I have another problem: if I delete and set in the same mutation and old and new owners are the same, then delete overwrites set. So I lose relation between device and owner.
What to do in this case?

I think it is related to this bug, that ~reverse doesn’t update correctly: https://github.com/dgraph-io/dgraph/issues/5732

Hey @poketulhu, your mutation looks good to me. Ideally, your mutation should set the <owner> to the new owner and delete the reverse edge for the previous owner to the device. There is a bug that @reverse edge is not being updated correctly which @ppp225 has pointed out.

So there’s no need to delete before the update? Is the estimated deadline for fixing this bug known?

Yes,there is no need to delete in your case.

Our team will try to pick up this ASAP.

Many thanks for the help!