From 36cd5a7a7882a32b175153941d26e63ffe4d508c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Mon, 9 Nov 2015 16:01:43 +0100 Subject: [PATCH] lib/registry: fix findModel for model ctor Fix `registry.findModel(arg)` to support the case when `arg` is already a model constructor. --- lib/registry.js | 2 +- test/loopback.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/registry.js b/lib/registry.js index 95fac6fa..ade0e2e8 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -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]; }; diff --git a/test/loopback.test.js b/test/loopback.test.js index ce45aa14..63d61d14 100644 --- a/test/loopback.test.js +++ b/test/loopback.test.js @@ -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', {}, {