我的模型看起来像这样:
let Family = sequelize.define('Family', {
name: { type: DataTypes.STRING, allowNull: false }});
let Person = sequelize.define('Person', {
firstName: { type: DataTypes.STRING, allowNull: false },
lastName: { type: DataTypes.STRING, allowNull: false }});
let PersonFamily = sequelize.define('PersonFamily', {
extraInfo: { type: DataTypes.JSONB }});
let Relationship = sequelize.define('Relationship', {
name: { type: DataTypes.STRING, allowNull: false }});
Relationship.hasMany(PersonFamily);
PersonFamily.belongsTo(Relationship, { foreignKey: { allowNull: false } });
Person.belongsToMany(Family, { through: PersonFamily, as: 'families' });
Family.belongsToMany(Person, { through: PersonFamily, as: 'members' });
我希望将所有成员和他们的关系拉出所有家庭。我试过这个:
Family.findById(fid,{include: [{model:Person ,as: 'members'}]}
//works but does not pull the relationship name
和这个
Family.findById(fid,{include: [{model:Person ,as: 'members', include: PersonFamily}]}
//does not work ... error
任何想法我怎样才能拉出关系名称?