Skip to content

Commit

Permalink
reset nested query expression (#155)
Browse files Browse the repository at this point in the history
* reset nested query expression

* 2.14.2
  • Loading branch information
kbarbounakis authored Aug 23, 2024
1 parent c8bd147 commit ebfc63b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
30 changes: 16 additions & 14 deletions OnNestedQueryOptionsListener.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { QueryExpression } = require('@themost/query');
const { QueryExpression, QueryField } = require('@themost/query');
// eslint-disable-next-line no-unused-vars
const { DataEventArgs } = require('./types');
const { instanceOf } = require('./instance-of');
Expand Down Expand Up @@ -106,26 +106,28 @@ class OnNestedQueryOptionsListener {
const nestedModel = context.model(item.$entity.model);
// if model exists
if (nestedModel != null) {
if (item.$entity.$as != null) {
// change view to follow entity alias defined by the current query
// this operation will be used while parsing filter and creating a new query expression
nestedModel.view = item.$entity.$as;
}
return nestedModel.filterAsync(options).then((q) => {
/**
* @typedef {object} QueryExpressionWithPrepared
* @property {*} $prepared
*/
/** @type {QueryExpressionWithPrepared} */
const { query } = q;
if (query && query.$prepared) {
item.$with = {
$and: [
item.$with,
query.$prepared
]
}
}
const collection = item.$entity.name;
Object.assign(item, {
$entity: Object.assign(query, {
$select: {
[collection]: [
new QueryField({
$name: collection.concat('.*')
})
]
},
$alias: item.$entity.$as,
$join: item.$entity.$join,
}),
model: item.$entity.model
})
return Promise.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.14.1",
"version": "2.14.2",
"description": "MOST Web Framework Codename Blueshift - Data module",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit ebfc63b

Please sign in to comment.