Edgedb链接更新失败:禁止修改计算型链接问题求助
解决Edgedb更新Student关联Class时的"computed link"错误
问题原因
你在with子句的查询中,显式指定了class的嵌套返回字段(id, name, year),这会让student_to_update变量里的class变成一个计算链接(computed link),而非原始的可修改链接字段,因此更新操作会被禁止。
正确查询写法
不需要在前置查询中嵌套获取class的详细字段,直接选中Student对象本身即可:
with student_to_update := ( select Student filter .id = <uuid>$student_id ) update student_to_update set {class := (select Class filter .id = <uuid>$class_id)};
或者更简化的写法,直接在update语句中过滤目标学生:
update Student filter .id = <uuid>$student_id set {class := (select Class filter .id = <uuid>$class_id)};
说明
当你在select语句中定义class: {id, name, year}时,相当于创建了一个临时的计算属性,覆盖了Student类型原本的class链接字段。这种临时计算字段是只读的,无法通过update修改。只要保持查询返回的是原始的Student对象(不额外定义嵌套字段),就能正常修改其class链接。
内容的提问来源于stack exchange,提问作者Alexey Sherchenkov
相关产品推荐
相关产品推荐

