-
Notifications
You must be signed in to change notification settings - Fork 1
Mixins
Michael Rüfenacht edited this page Jul 10, 2018
·
4 revisions
Loopback Mixins are defined as a function within your mixins folder (my-mixin.js):
module.exports = function(model, options){
// do your magic
}To make the Mixins available to the models one has to either add the source dir (or the files) to the _meta section of the model-config.json:
{
"_meta": {
"mixins": [
"loopback/server/mixins",
"../mixindir/relative/to/the/appRootDir",
"@joinbox/thingy/mixins/whuat"
]
}
}To hook in your mixin to a model, you can add it to the model's mixin section of the definition file (your-model.json.
Loopback will convert the file name of your mixin to Pascal Case and use it as the identifier to reference it.
{
"name": "YourModel",
"mixins": {
"MyMixin": {
"optionValue": true
}
}
}Note: You don't have to specify options, you can just set the value of "MyMixin" to true.