Skip to content

Commit

Permalink
Fix data mapping extender errors (#206)
Browse files Browse the repository at this point in the history
* fox data mapping extender errors

* fix data queryable error

* 2.6.80
  • Loading branch information
kbarbounakis authored Feb 12, 2025
1 parent 117bdab commit 821c0c6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
18 changes: 10 additions & 8 deletions data-mapping-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var {QueryField} = require('@themost/query');
var Q = require('q');
var {hasOwnProperty} = require('./has-own-property');
var {isObjectDeep} = require('./is-object');
var {DataError} = require('@themost/common')

class DataMappingExtender {
constructor(mapping) {
Expand Down Expand Up @@ -60,7 +61,7 @@ class DataMappingExtender {
return resolve();
}
if (_.isNil(thisQueryable)) {
return reject('The underlying data queryable cannot be empty at this context.');
return reject(new Error('The underlying data queryable cannot be empty at this context.'));
}
if ((mapping.childModel !== thisQueryable.model.name) || (mapping.associationType!=='junction')) {
return resolve();
Expand Down Expand Up @@ -341,7 +342,7 @@ class DataMappingExtender {
var childField = thisQueryable.model.field(mapping.childField);
var keyField = childField.property || childField.name;
if (_.isNil(childField)) {
return reject('The specified field cannot be found on child model');
return reject(new DataError('E_ATTR', `The specified field "${mapping.childField}" cannot be found in child model "${mapping.childModel}"`, null, mapping.childModel, mapping.childField));
}
var childFieldType = thisQueryable.model.context.model(childField.type);
var values = _.intersection(_.map(_.filter(arr, function(x) {
Expand Down Expand Up @@ -430,7 +431,7 @@ class DataMappingExtender {
if (err) { return reject(err); }
var parentField = thisQueryable.model.field(mapping.parentField);
if (_.isNil(parentField)) {
return reject('The specified field cannot be found on parent model');
return reject(new DataError('E_ATTR', `The specified field "${mapping.parentField}" cannot be found in parent model "${mapping.parentModel}"`, null, mapping.parentModel, mapping.parentField));
}
var keyField = parentField.property || parentField.name;
var parentFieldType = thisQueryable.model.context.model(parentField.type);
Expand All @@ -450,14 +451,15 @@ class DataMappingExtender {
if (values.length===0) {
return resolve();
}
const childModel = thisArg.getChildModel();
//search for view named summary
thisArg.getChildModel().filter(mapping.options, function(err, q) {
childModel.filter(mapping.options, function(err, q) {
if (err) {
return reject(err);
}
var childField = thisArg.getChildModel().field(mapping.childField);
var childField = childModel.field(mapping.childField);
if (_.isNil(childField)) {
return reject('The specified field cannot be found on child model');
return reject(new DataError('E_ATTR', `The specified field "${mapping.childField}" cannot be found in child model "${mapping.childModel}"`, null, mapping.childModel, mapping.childField));
}
var foreignKeyField = childField.property || childField.name;
//Important Backward compatibility issue (<1.8.0)
Expand Down Expand Up @@ -892,7 +894,7 @@ class DataMappingOptimizedExtender extends DataMappingExtender {
}
var parentField = thisArg.getParentModel().field(mapping.parentField);
if (parentField == null) {
return reject('The specified field cannot be found on parent model');
return reject(new DataError('E_ATTR', `The specified field "${mapping.parentField}" cannot be found in parent model "${mapping.parentModel}"`, null, mapping.parentModel, mapping.parentField));
}
var keyField = parentField.property || parentField.name;
var parentFieldType = thisQueryable.model.context.model(parentField.type);
Expand Down Expand Up @@ -921,7 +923,7 @@ class DataMappingOptimizedExtender extends DataMappingExtender {
}
var childField = thisArg.getChildModel().field(mapping.childField);
if (childField == null) {
return reject('The specified field cannot be found on child model');
return reject(new DataError('E_ATTR', `The specified field "${mapping.childField}" cannot be found in child model "${mapping.childModel}"`, null, mapping.childModel, mapping.childField));
}
var foreignKeyField = childField.property || childField.name;
//Important Backward compatibility issue (<1.8.0)
Expand Down
3 changes: 2 additions & 1 deletion data-queryable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,8 @@ function afterExecute_(result, callback) {
}
}
else {
return cb(new DataError('EASSOC', sprintf('Data association mapping (%s) for %s cannot be found or the association between these two models defined more than once.', expand, self.model.title)));
const expandName = typeof expand === 'string' ? expand : expand && expand.name;
return cb(new DataError('EASSOC', sprintf('Data association mapping (%s) for %s cannot be found or the association between these two models defined more than once.', expandName, self.model.name)));
}
}, function(err) {
if (err) {
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.79",
"version": "2.6.80",
"description": "MOST Web Framework Codename Blueshift - Data module",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 821c0c6

Please sign in to comment.