1

I am creating a test for my models, now my scenario is I want to insert to a table with a column/field that is not defined on my Sequelize schema.

Here is my sample for my schema

class ResploginSchema extends Sequelize.Model { }
ResploginSchema.init(
    {
        resploginID: {
            type: Sequelize.BIGINT(20).UNSIGNED,
            autoIncrement: true,
            primaryKey: true,
            allowNull: false
        },
        clientID: {
            type: Sequelize.INTEGER(10).UNSIGNED,
            allowNull: false,
            validate: {
                isNumeric: true
            }
        },
        tablelimitID: {
            type: Sequelize.TINYINT(2).UNSIGNED,
            allowNull: false
        },
        errMsgID: {
            type: Sequelize.INTEGER(6).UNSIGNED,
            allowNull: false
        }
    },
    {
        sequelize: dbConnection,
        modelName: "resplogin",
        freezeTableName: true,
        timestamps: false
    }
);

Here is the sample data I want to insert

let data = {
            clientID: 1,
            sessionID: "not defined field",
            tablelimitID: 1,
            errMsgID: 0
        };


ResploginSchema.create(data)

I was expecting that it should return an error saying that the sessionID is not defined on the model definition.

Maybe I missed some configuration on the model. Thanks in advance

Sequelize version : 5.21.3

Node Version : 10.14.2

Naor Levi
  • 1,713
  • 1
  • 13
  • 27
Oli Soproni B.
  • 2,774
  • 3
  • 22
  • 47

1 Answers1

0

This is expected behavior. Sequelize will only try and find the fields in the schema it does not care if there are other fields. In fact there are many cases where you may need virtual fields that are not stored in the database, but you may use in your business logic.

RedJandal
  • 1,203
  • 10
  • 18