我有点困惑,如何使用hasOne,hasMany和belongsTo在sequelize . 以及将这些连接用于外键的位置 . 这是我的3个表型号: User.js
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('user', {
ssid: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
}
});
return User;
}
serviceRgistration.js
module.exports = function(sequelize, DataTypes) {
var ServiceRegistration = sequelize.define('serviceRegistration', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userSsid: {
type: DataTypes.INTEGER,
references: {
model: 'users',
key: 'ssid'
}
},
serviceId: {
type: DataTypes.INTEGER,
references: {
model: 'services',
key: 'id'
}
}
});
return ServiceRegistration;
};
Service.js
module.exports = function(sequelize, DataTypes) {
var Service = sequelize.define('service', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
serviceName: {
type: DataTypes.STRING,
allowNull: true
},
serviceType: {
type: DataTypes.STRING,
allowNull: true
},
price: {
type: DataTypes.INTEGER,
allowNull: true
}
});
return Service;
};
我想加入所有三个表 . Any help?