admin管理员组文章数量:1122832
I asked ChatGPT whether Sequelize update or create will ignore extra attributes passed to it.
I have this code and unknownField
is indeed ignored. The data does not cause a db error.
const data = {
name: 'John Doe',
email: '[email protected]'
unknownField: 'This field should be ignored',
}
await person.update(data, { transaction })
As per ChatGPT:
3. Enforcing Fields via Model Definition If you are inserting or updating records, Sequelize will only allow fields defined in the model by default. If your data object contains additional fields, they will be ignored unless you use the allowNull or defaultValue properties for those fields.
But, when I asked to provide the source, it says
My explanation in 3. Enforcing Fields via Model Definition is based on how Sequelize models typically work according to its documentation and general usage patterns.
And I was surprised that I could not quickly find it in Sequelize docs. Can anyone point me to any article or documentation about Sequelize ignoring attributes if they are not defined in the model.
本文标签: sequelizejsDocumentation about Sequelize ignoring unknown attributesStack Overflow
版权声明:本文标题:sequelize.js - Documentation about Sequelize ignoring unknown attributes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736309545a1934059.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论