You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
File: ORM.js
Function: ORM.prototype.load
Issue:
Function load does not return any value when it is success. It is OK when model is loaded with instance of connect function. However, it has some problem using with express function.
In below code, novalue has undefined, because the load function doesn't return. It results in work-around code such as models.user = db.models.user;.
However, it'd be better that models.user = db.load ....
exports.db=orm.express(options,{define: function(db,models){varnovalue=db.load('./models/user',function(err){if(err){console.log('Fail to load model');throwerr;}returndb.models.user;/* HAVE NO EFFECT */});models.user=db.models.user;}});
Still, it's async. After the require, it will call the module and expect a callback to be invoked, which you could for example use to load things from the network, database, ...
You can of course use it sync, I'm going to change it to return the returned value from the function so you can use it if you want, but that's entirely up to you to create that logic.
Activity
vendethiel commentedon Jun 10, 2013
That's how async works.
ijsong commentedon Jun 10, 2013
The load is blocking call. So the caller is stopped until require(file)(this, cb) is done.
vendethiel commentedon Jun 10, 2013
That's true, my bad. I blindly assumed that since it uses a callback.
dresende commentedon Jun 11, 2013
Still, it's async. After the require, it will call the module and expect a callback to be invoked, which you could for example use to load things from the network, database, ...
You can of course use it sync, I'm going to change it to return the returned value from the function so you can use it if you want, but that's entirely up to you to create that logic.
Changes db.load() to return value from loaded and invoked function (#194