From 4e5cbe43f98ea8159e02cbe7f75e643aa1d135b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Sat, 29 Nov 2014 12:05:12 +0100 Subject: [PATCH] model-helper: ignore unknown property types --- lib/model-helper.js | 9 ++++++++- test/model-helper.test.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/model-helper.js b/lib/model-helper.js index 598f0f1..faee5b4 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -21,8 +21,15 @@ var modelHelper = module.exports = { */ generateModelDefinition: function generateModelDefinition(modelClass, definitions) { var def = modelClass.definition; - var name = def.name; var out = definitions || {}; + + if (!def) { + // The model does not have any definition, it was most likely + // created as a placeholder for an unknown property type + return out; + } + + var name = def.name; if (out[name]) { // The model is already included return out; diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 1fb6414..abe8586 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -198,6 +198,18 @@ describe('model-helper', function() { expect(Object.keys(defs)).has.property('length', 1); }); + // https://github.com/strongloop/loopback-explorer/issues/71 + it('should skip unknown types', function() { + var Model8 = loopback.createModel('Model8', { + patient: { + model: 'physician', + type: 'hasMany', + through: 'appointment' + } + }); + var defs = modelHelper.generateModelDefinition(Model8, {}); + expect(Object.keys(defs)).to.not.contain('hasMany'); + }); }); describe('hidden properties', function() {