apply mixin to models dynamically
I want to apply a mixin to my models including built in models dynamically , i.e in some boot script , right now I am using modelname.mixin('
How to resolve it?
Initialize mixin in server.js file
require(mixin)(app)
hi @padelagani I did not get you should I give path to mixin where you have mentioned mixin and whattshould i give in app, and should i require it in a variable? Can you please be more clear
@lokeshjain20 Keep that line in server.js after - var app = loopback()
var app = loopback()
require(mixin)(app)
@padelagani doing this gives me error - "mixin is not defined".
In mixin define your mixin name if it is from npm module else give path of that mixin
giving path name , does not give any error , but still mixin does not get applied to my models , when I am doing model.mixin('mixinName') , in my boot script.
i got it working finally , instead of model.mixin , var mixin = "/path of mixin"; and then require(mixin)(
@padelagani thank you for help , can you please explain what this line :require(mixin)(app/model) actualy does? Till now I have only used require with file path or module name , but never gave two brackets after require , what does it do?
@lokeshjain20 It passes loopback app instance to that mixin.
() because that module might be function module so to initialize that we need to call in that way.
When module.exports, exports a function then we call in that way.
@lokeshjain20 Can you close this issue or mark is at done
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.