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