Awesome
This package has been deprecated: Bookshelf support is now included in the factory-girl package
factory-girl-bookshelf
A Bookshelf adapter for factory-girl.
Usage
require('factory-girl-bookshelf')();
Or, if you want to specify which models it should be used for:
require('factory-girl-bookshelf')(['User', 'Foo', 'Bar']);
Relationships can be created using assoc
:
var Model = Bookshelf.db.Model;
var Parent = Model.extend({
children: function() {
return this.hasMany(Child, 'parent_id');
}
});
var Child = Model.extend({
parent: function() {
return this.belongsTo(Parent, 'parent_id');
}
});
factory.define('parent', Parent);
factory.define('child', Child, {
parent_id: factory.assoc('parent', 'id')
});