好吧,我现在已经盯着它看了2个小时,我根本找不到错误:
我有以下数据库表:
如果你不能告诉它有4列:
使用sequelize我使用以下代码:
var Competence = sequelize.define('competence', {
id: DataTypes.INTEGER,
name: DataTypes.STRING,
organization_id: DataTypes.INTEGER,
competence_type_id: DataTypes.INTEGER
}, {
freezeTableName: true,
instanceMethods: {
retrieveAll: function (org_id,onSuccess, onError) {
Location.findAll({where: {organization_id: org_id}}, {})
.ok(onSuccess).error(onError);
},
retrieveById: function (quote_id, onSuccess, onError) {
Location.find({where: {id: quote_id}}, {raw: true})
.success(onSuccess).error(onError);
},
add: function (onSuccess, onError) {
var competence = this.dataValues;
Competence.build(competence)
.save().ok(onSuccess).error(onError);
},
updateById: function (quote_id, onSuccess, onError) {
var id = quote_id;
var quotes = this.quotes;
Location.update({quotes: quotes}, {where: {id: id}})
.success(onSuccess).error(onError);
},
removeById: function (quote_id, onSuccess, onError) {
Location.destroy({where: {id: quote_id}}).success(onSuccess).error(onError);
}
}
}
),
competence_type = sequelize.define('competence_type', {
id: DataTypes.INTEGER,
name: DataTypes.STRING
});
Competence.belongsTo(competence_type,{foreignKey: 'competence_type_id'});
注意add函数,它是我用来添加新元素的函数。
这是我的competence
变量:
但是,一旦我保存,我的回调函数不会被调用onSuccess
也不会onError
任何人都可以帮助我,我会疯了!!