Protected against non-Model generation requests

This commit is contained in:
Shelby Sanders 2014-10-07 16:52:27 -07:00
parent 7f4e8b3f87
commit fd30b2d151
1 changed files with 12 additions and 16 deletions

View File

@ -24,13 +24,11 @@ var modelHelper = module.exports = {
modelName = modelName.replace(/[\[\]]/g, ''); modelName = modelName.replace(/[\[\]]/g, '');
} }
var model = app.models[modelName]; var model = app.models[modelName];
if (model) { if (model && referencedModels.indexOf(model) === -1) {
if (referencedModels.indexOf(model) === -1) {
referencedModels.push(model); referencedModels.push(model);
} }
} }
} }
}
var def = modelClass.definition; var def = modelClass.definition;
var name = def.name; var name = def.name;
@ -49,7 +47,7 @@ var modelHelper = module.exports = {
for (var m in def.settings.models) { for (var m in def.settings.models) {
var model = modelClass[m]; var model = modelClass[m];
if (typeof model === 'function' && model.modelName) { if (typeof model === 'function' && model.modelName) {
if (referencedModels.indexOf(model) === -1) { if (model && referencedModels.indexOf(model) === -1) {
referencedModels.push(model); referencedModels.push(model);
} }
} }
@ -113,17 +111,13 @@ var modelHelper = module.exports = {
// Generate model definitions for related models // Generate model definitions for related models
for (var r in modelClass.relations) { for (var r in modelClass.relations) {
var rel = modelClass.relations[r]; var rel = modelClass.relations[r];
if (rel.modelTo){ if (rel.modelTo && referencedModels.indexOf(rel.modelTo) === -1) {
if (referencedModels.indexOf(rel.modelTo) === -1) {
referencedModels.push(rel.modelTo); referencedModels.push(rel.modelTo);
} }
} if (rel.modelThrough && referencedModels.indexOf(rel.modelThrough) === -1) {
if (rel.modelThrough) {
if (referencedModels.indexOf(rel.modelThrough) === -1) {
referencedModels.push(rel.modelThrough); referencedModels.push(rel.modelThrough);
} }
} }
}
if (modelClass.sharedClass) { if (modelClass.sharedClass) {
var remotes = modelClass.sharedClass.methods(); var remotes = modelClass.sharedClass.methods();
@ -151,8 +145,10 @@ var modelHelper = module.exports = {
} }
for (var i = 0, n = referencedModels.length; i < n; i++) { for (var i = 0, n = referencedModels.length; i < n; i++) {
if (referencedModels[i].definition) {
generateModelDefinition(referencedModels[i], out); generateModelDefinition(referencedModels[i], out);
} }
}
return out; return out;
}, },