edgedb / easy-edgedb

An illustrated textbook designed to be a one-stop shop for learning EdgeDB
https://www.edgedb.com/easy-edgedb
69 stars 36 forks source link

Chapter 6 Update Error #86

Closed smcmill2 closed 1 year ago

smcmill2 commented 1 year ago

In Chapter 6 the UPDATE to Jonathan Harker

UPDATE Person FILTER .name = 'Jonathan Harker'
SET {
  lover := assert_single(
    (SELECT DETACHED Person FILTER .name = 'Mina Murray')
  )
};

does not in fact yield an updated entry.

SELECT Person {
  name,
  lover: {
    name
  }
} FILTER .name = 'Jonathan Harker';

results in

[
  {
    "name": "Jonathan Harker",
    "lover": null
  }
]

I was however able to get it to correctly update by casting to Person as in the following.

SELECT (
  UPDATE Person
  FILTER .name = 'Jonathan Harker'
  SET {
    lover := <Person>(SELECT assert_single((SELECT DETACHED Person FILTER .name = 'Mina Murray')))
  }
) {
  name,
  lover: {
    name
  }
}

which then yields.

[
  {
    "name": "Jonathan Harker",
    "lover": {
      "name": "Mina Murray"
    }
  }
]

I'm not sure whether this relates to this pull request or not, but may warrant updating the docs/code.

Dhghomon commented 1 year ago

Had a go through the schema + inserts today as they stand for the chapter and I see the updated entry as expected so will close the issue now.