A(1) - > B(many) - > C(many) - > D(many)のようなデータモデルをお持ちで、 Dのオブジェクトは、しかし、あなたはAの基準を持って、どのようにそれを行うことができますか?ここ条件を指定してmulitipleテーブルに結合する本棚クエリ
詳細は:
const Contact = bookshelf.Model.extend({
sites: function() {
return this.hasMany(Site);
},
});
const Contacts = bookshelf.Collection.extend({
model: Contact,
});
const Site = bookshelf.Model.extend({
siteAttendances: function() {
return this.hasMany(SiteAttendance);
},
siteSupervisor: function() {
return this.belongsTo(Contact);
},
});
const Sites = bookshelf.Collection.extend({
model: Site,
});
const SiteAttendance = bookshelf.Model.extend({
site: function() {
return this.belongsTo(Site);
},
incidents: function() {
return this.hasMany(Incident);
},
});
const SiteAttendances = bookshelf.Collection.extend({
model: SiteAttendance,
});
const Incident = bookshelf.Model.extend({
siteAttendance: function() {
return this.belongsTo(SiteAttendance);
}
});
const Incidents = bookshelf.Collection.extend({
model: Incident,
});
私は連絡先のID(オブジェクト)を持っているが、私は、インシデント(Dオブジェクト)のオブジェクトをしたいと私は唯一の本棚でこれを行うことができ、私は思ったんだけど。 js?物事を複雑にするために、すべての連絡先について、多くのインシデントだけがサイトとSiteAttendanceがあります。 1つの連絡先IDで多くのサイトが生成されるため、through
を使用してインシデントからサイトに送信する方法があるかもしれませんが、それを動作させることはできませんでした。私は連絡先から始めてwithRelated
をやっていないと正しいアプローチです(サイトやSiteAttendanceの数が多いので)が、間違っている可能性があります。
これは私が考えたものです。このようなことについては、ブックシェルフにぶつかってknex vsに脱落することについてコンセンサスがありますか? – ricka