Merge pull request #77 from strongloop/fix/skip-unknown-property-types

model-helper: ignore unknown property types
This commit is contained in:
Miroslav Bajtoš 2014-11-29 12:10:15 +01:00
commit 738928e622
2 changed files with 20 additions and 1 deletions

View File

@ -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;

View File

@ -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() {