lib/registry: fix findModel for model ctor

Fix `registry.findModel(arg)` to support the case when `arg` is already
a model constructor.
This commit is contained in:
Miroslav Bajtoš 2015-11-09 16:01:43 +01:00
parent e633617b8f
commit 36cd5a7a78
2 changed files with 2 additions and 1 deletions

View File

@ -284,7 +284,7 @@ Registry.prototype._defineRemoteMethods = function(ModelCtor, methods) {
* @header loopback.findModel(modelName)
*/
Registry.prototype.findModel = function(modelName) {
if (typeof modelType === 'function') return modelName;
if (typeof modelName === 'function') return modelName;
return this.modelBuilder.models[modelName];
};

View File

@ -245,6 +245,7 @@ describe('loopback', function() {
assert(loopback.getModel('MyModel') === MyModel);
assert(loopback.getModel('MyCustomModel') === MyCustomModel);
assert(loopback.findModel('Invalid') === undefined);
assert(loopback.getModel(MyModel) === MyModel);
});
it('should be able to get model by type', function() {
var MyModel = loopback.createModel('MyModel', {}, {