mardi 4 août 2015

Sequelize error on model.update

Unhandled rejection TypeError: undefined is not a function

error whe i am trying to update my table in sequelize above MySQL.

here is the snippet of code that triggering the error with commented one that surprisingly works:

topic.update(
        { name: "adfa"},
        { where: { tid: 1} }
);

//topicAttribute.update({ value: "name 2"},{where: {TOPIC: 2,name: "nadpis" }});

Now this is my two models:

var topic = sequelize.define('topic', {
        tid: {  type: Sequelize.INTEGER,
                field: 'tid',
                primaryKey: true                    
        },
        name: { type: Sequelize.STRING,
                field: 'name'       
        },
        added: {    type: Sequelize.DATE,
                    field: 'added'
        },
        addedBy: {  type: Sequelize.STRING,
                    field: 'added_by'
        },
        changed: {  type: Sequelize.DATE,
                    field: 'changed'
        },
        changedBy: {    type: Sequelize.STRING,
                        field: 'changed_by'
        },
        parent: {   type:   Sequelize.INTEGER,
                    field: 'parent'
        },
        enabled: {
                    type:   Sequelize.BOOLEAN,
                    field: 'enabled'
        }
    },
{
        tableName: 'topic',
        timestamps: false
});

var topicAttribute = sequelize.define('tAttribute', {
    parent: {   type: Sequelize.INTEGER,
            field: 'TOPIC',
            primaryKey: true
    },
    name: { type: Sequelize.STRING,
            field: 'name',
            primaryKey: true
    },
    value: {    type: Sequelize.STRING,
                field: 'value'
    },
},
{
    tableName: 'topic_attribute',
    timestamps: false
});

topic.hasOne(topic, {foreignKey: 'tid'});
topic.hasMany(topicAttribute, {foreignKey: 'parent'});
topicAttribute.belongsTo(topic, {foreignKey: 'parent'});

And finally my stacktrace:

Unhandled rejection TypeError: undefined is not a function  
at Instance.set (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:365:16)
at Instance.set (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:293:16)
at initValues (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:63:8) 
at Instance (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\instance.js:107:14) 
at new Instance (C:\Users\212443162\Documents\ithd\node_modules\sequelize\li b\model.js:655:14) 
at Model.build (C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\model.js:1493:10) 
at C:\Users\212443162\Documents\ithd\node_modules\sequelize\lib\model.js:2119:24 
at tryCatcher (C:\Users\212443162\Documents\ithd\node_modules\sequelize\node_modules\bluebird\js\main\util.js:24:31) 
at Function.Promise.attempt.Promise.try (C:\Users\212443162\Documents\ithd\node_modules\sequelize\node_modules\bluebird\js\main\method.js:31:24)    
at Model.update (C:\Users\212443162\Documents\ithd\node_modules\sequelize\li b\model.js:2116:21) 
at C:\Users\212443162\Documents\ithd\routes\topics.js:119:8 at Layer.handle [as handle_request] (C:\Users\212443162\Documents\ithd\node_ modules\express\lib\router\layer.js:95:5) 
at next (C:\Users\212443162\Documents\ithd\node_modules\express\lib\router\r oute.js:131:13) 
at Route.dispatch (C:\Users\212443162\Documents\ithd\node_modules\express\li b\router\route.js:112:3) 
at Layer.handle [as handle_request] (C:\Users\212443162\Documents\ithd\node_ modules\express\lib\router\layer.js:95:5) 
at C:\Users\212443162\Documents\ithd\node_modules\express\lib\router\index.j s:277:22



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire