Assuming I have this:
var Ad = base.Model.extend({
tableName: 'ads'
});
var Ads = base.Collection.extend({
model: Ad
});
module.exports = {
Ad: base.model('Ad', Ad),
Ads: base.collection('Ads', Ads)
};
and I need to return a collection of ads matching certain criteria. I can do it two ways:
// Option 1: via collection
Ads
.query({
where: {
classified_id: query.classId, section_id: query.secId, category_id: query.catId
}
})
.fetch()
.then(function(results) {
// ... ... ...
});
// Option 2: via a Model and fetchAll()
Ad
.where({
classified_id: query.classId, section_id: query.secId, category_id: query.catId
})
.fetchAll()
.then(function(results) {
// ... ... ...
});
Are these both pretty much the same, or is one way preferred than the other?
Stick to the latter. We're looking to pull the collections API ASAP. It's too heavy and as you've noticed the shift towards exposing Active Record style methods on models has already started.
:+1: I love this shift. Thank you!
Stick to the latter. We're looking to pull the collections API ASAP. It's too heavy and as you've noticed the shift towards exposing Active Record style methods on models has already started.
That was over a year ago. Whats the situation now?
That was over a year ago. Whats the situation now?
I'd like to know that too. Should I still keep using only Model?
Most helpful comment
That was over a year ago. Whats the situation now?