Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Last active August 29, 2015 13:56
Show Gist options
  • Save bendrucker/9274656 to your computer and use it in GitHub Desktop.
Save bendrucker/9274656 to your computer and use it in GitHub Desktop.
Default columns with a bookshelf collection
var ModelBase = Bookshelf.Model.extend();
var CollectionBase = Bookshelf.Collection.extend({
toJSON: function () {
var json = Bookshelf.Collection.toJSON.apply(this, arguments);
json.object = this.model.prototype.object;
return json;
});
});
Model.collection = function (models, options) {
return new CollectionBase(models || [], _.extend(options, {model: this}));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment