参考:https://docs.directus.io/reference/introduction.html#many-to-one
…To update an existing item, simply provide the primary key with the updates, and Directus will treat it as an update instead of a creation…
比如有一个 M2O 即“多到一”关联: category,而 category 下面有 id(主键)、name、slug,那么如果创建时不带 id 是新建一个 category,带上 id 则是更新已存在的数据,而且这里面如果设置了 name、slug 是唯一值,创建和返回值的时候需要得带上。
mutation {
create_game_item (data: {
title: "Abc"
slug: "abc"
content: "..."
category: {
id: 1
name: "Puzzle"
slug: "puzzle"
}
}) {
id
category {
name
slug
}
}
首次发布于:2024 年 4 月 2 日