Fixes in belongsTo relation definition syntax
This commit is contained in:
parent
d3752eab4c
commit
2749a1f7e0
20
lib/model.js
20
lib/model.js
|
@ -512,6 +512,12 @@ AbstractClass.include = function (objects, include, cb) {
|
||||||
}
|
}
|
||||||
var relation = relations[relationName];
|
var relation = relations[relationName];
|
||||||
|
|
||||||
|
if (!relation) {
|
||||||
|
return function() {
|
||||||
|
cb(new Error('Relation "' + relationName + '" is not defined for ' + self.modelName + ' model'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var req = {'where': {}};
|
var req = {'where': {}};
|
||||||
|
|
||||||
if (!keyVals[relation.keyFrom]) {
|
if (!keyVals[relation.keyFrom]) {
|
||||||
|
@ -957,10 +963,14 @@ AbstractClass.belongsTo = function (anotherClass, params) {
|
||||||
params = params || {};
|
params = params || {};
|
||||||
if ('string' === typeof anotherClass) {
|
if ('string' === typeof anotherClass) {
|
||||||
params.as = anotherClass;
|
params.as = anotherClass;
|
||||||
var anotherClassName = anotherClass.toLowerCase();
|
if (params.model) {
|
||||||
for(var name in this.schema.models) {
|
anotherClass = params.model;
|
||||||
if (name.toLowerCase() === anotherClassName) {
|
} else {
|
||||||
anotherClass = this.schema.models[name];
|
var anotherClassName = anotherClass.toLowerCase();
|
||||||
|
for(var name in this.schema.models) {
|
||||||
|
if (name.toLowerCase() === anotherClassName) {
|
||||||
|
anotherClass = this.schema.models[name];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -969,7 +979,7 @@ AbstractClass.belongsTo = function (anotherClass, params) {
|
||||||
|
|
||||||
this.relations[params['as']] = {
|
this.relations[params['as']] = {
|
||||||
type: 'belongsTo',
|
type: 'belongsTo',
|
||||||
keyFrom: params['foreignKey'],
|
keyFrom: fk,
|
||||||
keyTo: 'id',
|
keyTo: 'id',
|
||||||
modelTo: anotherClass,
|
modelTo: anotherClass,
|
||||||
multiple: false
|
multiple: false
|
||||||
|
|
Loading…
Reference in New Issue