年のような情報は、そのデータからテーブル名として保存しないでください。実際の使用可能なデータとして別のテーブルエントリとして格納する必要があります。
変更company_historical_<year>
はちょうどcompany_historical
だけ会社歴史エントリを持つことができるすべての可能な年を持ってcompany_historical_years
と呼ばれる新しいテーブルを作成します。
はその後会社歴史エントリと関連会社Historcal年エントリ間の関係を作成します。
だから、のようなもの:
var CompanyHistoricalYears = sequelize.define('company_historical_years', {
year: {
type: Sequelize.INTEGER
},
classMethods: {
associate: function (models) {
CompanyHistoricalYears.hasMany(models.CompanyHistorical);
}
}
};
var CompanyHistorical = sequelize.define('company_historical', {
...
classMethods: {
associate: function (models) {
CompanyHistorical.belongsTo(models.CompanyHistoricalYears);
}
}
};
、その後、あなたがそれを照会できます。これはあなたの単一CompanyHistoricalYears
エントリと、その年の範囲内にあるすべてのCompanyHistorical
エントリを与える
CompanyHistoricalYears.findOne({
where: {
year: 2011, // or you can use "new Date().getFullYear()"
},
include: [CompanyHistorical]
});
。
これ以外の場合は、質問をしてください。