upsertGraph 根据与 'id' 不同的列更新行
upsertGraph update rows based on different column than 'id'
我有一个包含 id
和 supplier_id
列的产品 table。
当我从供应商处获取产品时,如何使 upsertGraph
基于 supplier_id
而不是 id
更新行?
现在 upsertGraph
只使用插入,因为没有 id
属性 存在。
编辑
我从几个不同的供应商处获取产品列表,其中包含 id
、name
、price
我用 id
、name
、price
和 supplier_id
将产品存储在我的数据库中
因此,我正在尝试根据 supplier_id 制作 upsertGraph
update/insert,以根据 supplier_id 而不是 id.
更新产品
这可能吗?
之前没有尝试过,但我认为你可以使用 idColumn:
class Supplier extends Model {
static get idColumn() {
return 'supplier_id';
}
}
没有。
好吧,正如官方文档所述
upsertGraph
无法满足您的需求
By default upsertGraph method updates the objects that have an id,
inserts objects that don't have an id and deletes all objects that are
not present. This functionality can be modified in many ways by
providing UpsertGraphOptions object as the second argument.
REF:https://vincit.github.io/objection.js/guide/query-examples.html#graph-upserts
它提到可以修改默认功能,但是修改基于与 id
不同的列的搜索是不可能的。
我有一个包含 id
和 supplier_id
列的产品 table。
当我从供应商处获取产品时,如何使 upsertGraph
基于 supplier_id
而不是 id
更新行?
现在 upsertGraph
只使用插入,因为没有 id
属性 存在。
编辑
我从几个不同的供应商处获取产品列表,其中包含 id
、name
、price
我用 id
、name
、price
和 supplier_id
因此,我正在尝试根据 supplier_id 制作 upsertGraph
update/insert,以根据 supplier_id 而不是 id.
这可能吗?
之前没有尝试过,但我认为你可以使用 idColumn:
class Supplier extends Model {
static get idColumn() {
return 'supplier_id';
}
}
没有。
好吧,正如官方文档所述
upsertGraph
无法满足您的需求
By default upsertGraph method updates the objects that have an id, inserts objects that don't have an id and deletes all objects that are not present. This functionality can be modified in many ways by providing UpsertGraphOptions object as the second argument.
REF:https://vincit.github.io/objection.js/guide/query-examples.html#graph-upserts
它提到可以修改默认功能,但是修改基于与 id
不同的列的搜索是不可能的。