Sequelize:强制更新 JSON 数组
Sequelize: Force update for JSON array
在某些情况下,Sequelize 不会更新 JSON 字段。
比如我有:
[[1]] (an array inside array)
我正在尝试推动一些事情:
instance.arr[0].push(1); // [[1,1]]
instance.save();
// or:
instance.update({arr: instance.arr});
现在我在实例内部更改了数组,而在数据库内部没有任何更改。甚至不发送查询。 :(
来自续集网站:
https://sequelize.org/master/manual/model-instances.html
The save method is optimized internally to only update fields that really
changed. This means that if you don't change anything and call save,
Sequelize will know that the save is superfluous and do nothing, i.e.,
no query will be generated (it will still return a Promise, but it
will resolve immediately).
很好,但似乎不适用于 json,我可以强制更新吗?
从今天开始,我必须对数组进行深拷贝才能保存它。
如果重要的话,我正在使用 MariaDB IDK。
看来你必须指定该字段已更改
instance.changed( 'arr', true);
instance.save
在某些情况下,Sequelize 不会更新 JSON 字段。
比如我有:
[[1]] (an array inside array)
我正在尝试推动一些事情:
instance.arr[0].push(1); // [[1,1]]
instance.save();
// or:
instance.update({arr: instance.arr});
现在我在实例内部更改了数组,而在数据库内部没有任何更改。甚至不发送查询。 :(
来自续集网站:
https://sequelize.org/master/manual/model-instances.html The save method is optimized internally to only update fields that really changed. This means that if you don't change anything and call save, Sequelize will know that the save is superfluous and do nothing, i.e., no query will be generated (it will still return a Promise, but it will resolve immediately).
很好,但似乎不适用于 json,我可以强制更新吗?
从今天开始,我必须对数组进行深拷贝才能保存它。
如果重要的话,我正在使用 MariaDB IDK。
看来你必须指定该字段已更改
instance.changed( 'arr', true);
instance.save