Handle hasMany.though
This commit is contained in:
parent
3b6070fe58
commit
43637a690d
28
lib/dao.js
28
lib/dao.js
|
@ -543,21 +543,27 @@ DataAccessObject.find = function find(params, cb) {
|
||||||
obj._initProperties(d, false, params.fields);
|
obj._initProperties(d, false, params.fields);
|
||||||
|
|
||||||
if (params && params.include) {
|
if (params && params.include) {
|
||||||
// Try to normalize the include
|
if (params.collect) {
|
||||||
var includes = params.include;
|
// Return the collected item for through models
|
||||||
if(typeof includes === 'string') {
|
obj = obj.__cachedRelations[params.collect];
|
||||||
includes = [includes];
|
} else {
|
||||||
} else if(typeof includes === 'object') {
|
// Try to normalize the include
|
||||||
includes = Object.keys(includes);
|
var includes = params.include || [];
|
||||||
|
if (typeof includes === 'string') {
|
||||||
|
includes = [includes];
|
||||||
|
} else if (typeof includes === 'object') {
|
||||||
|
includes = Object.keys(includes);
|
||||||
|
}
|
||||||
|
includes.forEach(function (inc) {
|
||||||
|
// Promote the included model as a direct property
|
||||||
|
obj.__data[inc] = obj.__cachedRelations[inc];
|
||||||
|
});
|
||||||
|
delete obj.__data.__cachedRelations;
|
||||||
}
|
}
|
||||||
includes.forEach(function (inc) {
|
|
||||||
// Promote the included model as a direct property
|
|
||||||
obj.__data[inc] = obj.__cachedRelations[inc];
|
|
||||||
});
|
|
||||||
delete obj.__data.__cachedRelations;
|
|
||||||
}
|
}
|
||||||
data[i] = obj;
|
data[i] = obj;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (data && data.countBeforeLimit) {
|
if (data && data.countBeforeLimit) {
|
||||||
data.countBeforeLimit = data.countBeforeLimit;
|
data.countBeforeLimit = data.countBeforeLimit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue