我有两个通过from subprocess import Popen ,PIPE
proc = Popen(['python.exe','ex1.py'], stdout=PIPE, stderr=PIPE)
out, err = proc.communicate()
print(out, err)
关系表链接的模型Company
和Contractor
。
company.js
CompanyContractor
contractor.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const Company = sequelize.define('Company', {
name: {
type: DataTypes.STRING(30),
allowNull: false,
unique: true
},
slug: {
type: DataTypes.STRING(30),
allowNull: false
},
description: DataTypes.STRING(200),
}, {});
Company.associate = function(models) {
Company.belongsToMany(models.Contractor, { through: 'CompanyContractor', as: 'contractors',foreignKey: 'companyId' });
};
return Company;
};
companyContractor.js
'use strict';
module.exports = (sequelize, DataTypes) => {
const Contractor = sequelize.define('Contractor', {
name: {
type: DataTypes.STRING(50),
allowNull: false
}
}, {});
Contractor.associate = function(models) {
Contractor.belongsToMany(models.Company, { through: 'CompanyContractor', as: 'contractors' });
};
return Contractor;
};
是否可以通过'use strict';
module.exports = (sequelize, DataTypes) => {
const CompanyContractor = sequelize.define('CompanyContractor', {
companyId: {
type: DataTypes.INTEGER,
allowNull: false
},
contractorId: {
type: DataTypes.INTEGER,
allowNull: false
}
}, {
timestamps: false
});
return CompanyContractor;
};
到Contractor.findAll()
?
答案 0 :(得分:0)
Contractor.findAll({
include: [{
model: Company,
through: {
attributes: ['companyId']
}
}]
});