我想在Bookshelf.js中创建多对多关系,并希望自己指定FK列的名称。我也希望能够访问Bookshelf中的helper-table,类似于:
NSSet
我该怎么做?
答案 0 :(得分:0)
考虑到上面的例子,可以这样做:
var Doctor = bookshelf.Model.extend({
patients: function() {
return this.belongsToMany(Patient).through(Appointment);
}
});
var Appointment = bookshelf.Model.extend({
patient: function() {
return this.belongsTo(Patient);
},
doctor: function() {
return this.belongsTo(Doctor);
}
});
var Patient = bookshelf.Model.extend({
doctors: function() {
return this.belongsToMany(Doctor).through(Appointment);
}
});