Vorrei ottenere typeName
attributo come parte del modello baffle
, senza recuperarlo da baffleType
in modo esplicito ogni volta.Recupera sempre dai modelli correlati in Bookshelf.js
le seguenti opere per me, ma sembra che withRelated
caricherà le relazioni se baffle
modello è direttamente inverosimile, non dalla relazione:
let baffle = bookshelf.Model.extend({
constructor: function() {
bookshelf.Model.apply(this, arguments);
this.on('fetching', function(model, attrs, options) {
options.withRelated = options.withRelated || [];
options.withRelated.push('type');
});
},
virtuals: {
typeName: {
get: function() {
return this.related('type').attributes.typeName;
}
}
},
type: function() {
return this.belongsTo(baffleType, 'type_id');
}
});
let baffleType = bookshelf.Model.extend({});
Qual è il modo corretto di farlo?
Grazie, non è mai troppo tardi. – estus