Is there a bookshelf.js (http://bookshelfjs.org/) equivalent to the 'default scope' in Rails?
For example, lets say I have the model "User":
User = Knex.Model.extend({
tableName: 'users'
});
Let's also say that the user's table has a boolean field called "verified". What I want to know is if there is a way to have a default scope such that when I query the users table,
collection.fetch().then(function(collection) {
// the collection contains only users with the verified = true attribute
})
the collection returned contains only users with the verified = true attribute
Bookshelf model (or any backbone model) allow extending both instance properties and
classProperties
.classProperties
attaches directly to the constructor function which is similar toActiveRecord
's scope methods.You can add
verified
method to User model's class properties like this.And use it like this.