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];
|
||||
|
||||
if (!relation) {
|
||||
return function() {
|
||||
cb(new Error('Relation "' + relationName + '" is not defined for ' + self.modelName + ' model'));
|
||||
}
|
||||
}
|
||||
|
||||
var req = {'where': {}};
|
||||
|
||||
if (!keyVals[relation.keyFrom]) {
|
||||
|
@ -957,10 +963,14 @@ AbstractClass.belongsTo = function (anotherClass, params) {
|
|||
params = params || {};
|
||||
if ('string' === typeof anotherClass) {
|
||||
params.as = anotherClass;
|
||||
var anotherClassName = anotherClass.toLowerCase();
|
||||
for(var name in this.schema.models) {
|
||||
if (name.toLowerCase() === anotherClassName) {
|
||||
anotherClass = this.schema.models[name];
|
||||
if (params.model) {
|
||||
anotherClass = params.model;
|
||||
} else {
|
||||
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']] = {
|
||||
type: 'belongsTo',
|
||||
keyFrom: params['foreignKey'],
|
||||
keyFrom: fk,
|
||||
keyTo: 'id',
|
||||
modelTo: anotherClass,
|
||||
multiple: false
|
||||
|
|
Loading…
Reference in New Issue