Skip to content
This repository has been archived by the owner on Oct 9, 2019. It is now read-only.

Commit

Permalink
Merge cc3f036 into 74eec33
Browse files Browse the repository at this point in the history
  • Loading branch information
pon committed Mar 1, 2015
2 parents 74eec33 + cc3f036 commit a4891ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ base: function (bookshelf) {
```

# Defining Models
There is more extensive documentation about defining models for the _registry_ plugin on the [Bookshelf.js Wiki](https://github.com/tgriesser/bookshelf/wiki/Plugin:-Model-Registry). Below is an example of defining two related models that can be placed in the ```models``` directory referenced above.
There is more extensive documentation about defining models for the _registry_ plugin on the [Bookshelf.js Wiki](https://github.com/tgriesser/bookshelf/wiki/Plugin:-Model-Registry). Below is an example of defining two related models that can be placed in the ```models``` directory referenced above. `baseModel` is the Bookshelf model created by the `base` option or just the basic Bookshelf model if you didn't define one. `bookshelf` is a Bookshelf instance with a connection to the database defined when the plugin was registered.
```javascript
// user.js
module.exports = function (bookshelf) {
return bookshelf.extend({
module.exports = function (baseModel, bookshelf) {
return baseModel.extend({
tableName: 'users',
roles: function () {
return this.belongsToMany('Role');
Expand All @@ -71,8 +71,8 @@ module.exports = function (bookshelf) {
};
// role.js
module.exports = function (bookshelf) {
return bookshelf.extend({
module.exports = function (baseModel, bookshelf) {
return baseModel.extend({
tableName: 'roles'
});
};
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.register = function (server, options, next) {
var modelName = path.basename(model).replace(path.extname(model), '');
modelName = modelName[0].toUpperCase() + modelName.substr(1);
bookshelf.model(modelName,
require(path.join(options.models, model))(baseModel));
require(path.join(options.models, model))(baseModel, bookshelf));
});

if (options.namespace) {
Expand Down

0 comments on commit a4891ad

Please sign in to comment.