Skip to content

Commit

Permalink
get values when passing objects (#204)
Browse files Browse the repository at this point in the history
* get values when passing objects

* 2.6.79
  • Loading branch information
kbarbounakis authored Feb 6, 2025
1 parent 7b27d71 commit 117bdab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
42 changes: 38 additions & 4 deletions data-mapping-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var {QueryEntity} = require('@themost/query');
var {QueryField} = require('@themost/query');
var Q = require('q');
var {hasOwnProperty} = require('./has-own-property');
var {isObjectDeep} = require('./is-object');

class DataMappingExtender {
constructor(mapping) {
Expand Down Expand Up @@ -342,9 +343,20 @@ class DataMappingExtender {
if (_.isNil(childField)) {
return reject('The specified field cannot be found on child model');
}
var childFieldType = thisQueryable.model.context.model(childField.type);
var values = _.intersection(_.map(_.filter(arr, function(x) {
return hasOwnProperty(x, keyField);
}), function (x) { return x[keyField];}));
}), function (x) { return x[keyField];})).map(function(x) {
if (isObjectDeep(x)) {
if (childFieldType) {
return x[childFieldType.primaryKey];
}
throw new Error('The child item is an object but its type cannot determined.');
}
return x;
}).filter(function(x) {
return x != null;
});
if (values.length===0) {
return resolve();
}
Expand Down Expand Up @@ -421,9 +433,20 @@ class DataMappingExtender {
return reject('The specified field cannot be found on parent model');
}
var keyField = parentField.property || parentField.name;
var parentFieldType = thisQueryable.model.context.model(parentField.type);
var values = _.intersection(_.map(_.filter(arr, function(x) {
return hasOwnProperty(x, keyField);
}), function (x) { return x[keyField];}));
}), function (x) { return x[keyField];})).map(function(x) {
if (isObjectDeep(x)) {
if (parentFieldType) {
return x[parentFieldType.primaryKey];
}
throw new Error('The parent item is an object but its type cannot determined.');
}
return x;
}).filter(function(x) {
return x != null;
});
if (values.length===0) {
return resolve();
}
Expand Down Expand Up @@ -528,7 +551,7 @@ class DataMappingExtender {
});
return resolve();
}).catch(function(err) {
return resolve(err);
return reject(err);
});
});
});
Expand Down Expand Up @@ -872,11 +895,22 @@ class DataMappingOptimizedExtender extends DataMappingExtender {
return reject('The specified field cannot be found on parent model');
}
var keyField = parentField.property || parentField.name;
var parentFieldType = thisQueryable.model.context.model(parentField.type);
var values = _.intersection(_.map(_.filter(arr, function(x) {
return hasOwnProperty(x, keyField);
}), function (x) {
return x[keyField];
}));
})).map(function(x) {
if (isObjectDeep(x)) {
if (parentFieldType) {
return x[parentFieldType.primaryKey];
}
throw new Error('The parent item is an object but its type cannot determined.');
}
return x;
}).filter(function(x) {
return x != null;
});;
if (values.length===0) {
return resolve();
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@themost/data",
"version": "2.6.78",
"version": "2.6.79",
"description": "MOST Web Framework Codename Blueshift - Data module",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 117bdab

Please sign in to comment.