mibrito / joi-sequelize

MIT License
27 stars 19 forks source link

model define throw "TypeError: DataTypes.ARRAY is not a function" #15

Open xjnotxj opened 6 years ago

xjnotxj commented 6 years ago

model define:

module.exports = (sequelize, DataTypes) => {
    var Student = sequelize.define('Student', { 
        residence: DataTypes.ARRAY(DataTypes.STRING),
    },
        {
            classMethods: {
                associate: function (models) {
                    // associations can be defined here
                }
            },
            underscored: true
        });

    return Student;
};

throw error:

/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/models/student.js:25
        residence: DataTypes.ARRAY(DataTypes.STRING),
                             ^

TypeError: DataTypes.ARRAY is not a function
    at module.exports (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/models/student.js:25:30)
    at new JoiSequelize (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/node_modules/joi-sequelize/index.js:14:3)
    at fs.readdirSync.filter.forEach.file (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/models/index.js:29:25)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/models/index.js:25:4)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/middleware/valication.js:3:16)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/xjnotxj/Program/NodeJsProject/sequelize_demo/backend/app.js:23:9)
    at Module._compile (module.js:635:30)
wkopen commented 5 years ago

Fixed in this PR: https://github.com/mibrito/joi-sequelize/pull/10. Waiting to be merged. @mibrito