模型用户如下:
module.exports = (sequelize, Sequelize) => {
var user = sequelize.define('user', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
});
user.associate = function (models) {
user.hasOne(models.oAuthAuthorizationToken, {foreignKey: 'userId', sourceKey: 'id'});
};
});
模型oAuthAuthorizationToken看起来像
module.exports = (sequelize, Sequelize) => {
var oauthAuthorizationToken = sequelize.define('oauthAuthorizationToken', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER
},
userId: {
type: Sequelize.UUID,
references: {
model: 'users',
key: 'id'
},
allownull: false,
}
});
oauthAuthorizationToken.associate = function(models) {
oauthAuthorizationToken.belongsTo(models.user, { foreignKey: 'userId', targetKey: 'id' });
};
return oauthAuthorizationToken;
};
错误为 SequelizeEagerLoadingError:用户未与oauthAuthorizationToken关联! 已经有一个问题,但这不能解决我的问题。谢谢