Created
May 6, 2018 09:12
-
-
Save fl0w/37c8a9a2b824a33bbb2cdb7abe845506 to your computer and use it in GitHub Desktop.
The correct way to define custom bookshelf Collections with registry plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const bookshelf = require('bookshelf') | |
class Users extends bookshelf.Collection { | |
get model () { | |
return User | |
} | |
} | |
class User extends bookshelf.Model { | |
static collection (...args) { | |
return new Users(...args) | |
} | |
} | |
bookshelf.collection('Users', Users) | |
bookshelf.model('User', User) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This'll also allow to define custom logic when collection is eager loaded: