fix polymorphicName var scope
see https://github.com/strongloop/loopback-datasource-juggler/issues/271 Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
parent
7698f0f08b
commit
d43044c766
|
@ -392,6 +392,7 @@ DataSource.prototype.defineScopes = function (modelClass, scopes) {
|
||||||
* @param relations
|
* @param relations
|
||||||
*/
|
*/
|
||||||
DataSource.prototype.defineRelations = function (modelClass, relations) {
|
DataSource.prototype.defineRelations = function (modelClass, relations) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
// Create a function for the closure in the loop
|
// Create a function for the closure in the loop
|
||||||
var createListener = function (name, relation, targetModel, throughModel) {
|
var createListener = function (name, relation, targetModel, throughModel) {
|
||||||
|
@ -428,7 +429,7 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
|
||||||
|
|
||||||
// Set up the relations
|
// Set up the relations
|
||||||
if (relations) {
|
if (relations) {
|
||||||
for (var rn in relations) {
|
Object.keys(relations).forEach(function(rn) {
|
||||||
var r = relations[rn];
|
var r = relations[rn];
|
||||||
assert(DataSource.relationTypes.indexOf(r.type) !== -1, "Invalid relation type: " + r.type);
|
assert(DataSource.relationTypes.indexOf(r.type) !== -1, "Invalid relation type: " + r.type);
|
||||||
var targetModel, polymorphicName;
|
var targetModel, polymorphicName;
|
||||||
|
@ -447,12 +448,12 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.model) {
|
if (r.model) {
|
||||||
targetModel = isModelClass(r.model) ? r.model : this.getModel(r.model, true);
|
targetModel = isModelClass(r.model) ? r.model : self.getModel(r.model, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var throughModel = null;
|
var throughModel = null;
|
||||||
if (r.through) {
|
if (r.through) {
|
||||||
throughModel = isModelClass(r.through) ? r.through : this.getModel(r.through, true);
|
throughModel = isModelClass(r.through) ? r.through : self.getModel(r.through, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((targetModel && !isModelDataSourceAttached(targetModel))
|
if ((targetModel && !isModelDataSourceAttached(targetModel))
|
||||||
|
@ -469,7 +470,7 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
|
||||||
}
|
}
|
||||||
modelClass[r.type].call(modelClass, rn, params);
|
modelClass[r.type].call(modelClass, rn, params);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue