diff --git a/lib/model-helper.js b/lib/model-helper.js index e77e181..1fafcbd 100644 --- a/lib/model-helper.js +++ b/lib/model-helper.js @@ -72,10 +72,18 @@ var modelHelper = module.exports = { var propType = def.properties[key].type; if (typeof propType === 'function' && propType.modelName) { - if (referencedModels.indexOf(m) === -1) { + if (referencedModels.indexOf(propType) === -1) { referencedModels.push(propType); } } + if (Array.isArray(propType) && propType.length) { + var itemType = propType[0]; + if (typeof itemType === 'function' && itemType.modelName) { + if (referencedModels.indexOf(itemType) === -1) { + referencedModels.push(itemType); + } + } + } }); out[name] = { diff --git a/test/model-helper.test.js b/test/model-helper.test.js index 0686818..efe720a 100644 --- a/test/model-helper.test.js +++ b/test/model-helper.test.js @@ -153,6 +153,17 @@ describe('model-helper', function() { expect(defs).has.property('Model3'); expect(defs).has.property('Model4'); }); + + it('should include nesting models in array', function() { + var Model6 = loopback.createModel('Model6', {street: String}); + var Model5 = loopback.createModel('Model5', { + str: String, // 'string' + addresses: [Model6] + }); + var defs = modelHelper.generateModelDefinition(Model5, {}); + expect(defs).has.property('Model5'); + expect(defs).has.property('Model6'); + }); }); describe('hidden properties', function() {