我正在尝试掌握如何使用相关对象。
我有两个对象
UserAttributes
var sequelize = require('../database.js').sequelize,
Sequelize = require('../database.js').Sequelize,
User = sequelize.models.user,
UserAttribute = sequelize.define('userAttributes', {
name: Sequelize.STRING,
value: Sequelize.STRING,
});
UserAttribute.belongsTo(User);
module.exports = UserAttribute;
用户
User = sequelize.define('user', {},{
classMethods: {
createRider: function(params) {
var values = [],
userAttributes = sequelize.models.userAttributes,
user = User.build(),
name = userAttributes.build({name: 'name', value: 'params.name'}),
fbprofile = userAttributes.build({name: 'fbprofile', value: 'params.fbprofile'}),
phone = userAttributes.build({name: 'phone', value: 'params.phone'});
user.save().then((user) => {
console.log(user);
user.adduserAttributes([name, fbprofile, phone]);
});
}
}
});
由于某种原因,adduserAttributes不起作用。这是我在此发现的所有文档。