Comparing version 1.0.80 to 1.0.81
@@ -20,2 +20,3 @@ "use strict"; | ||
const get_nesting_where = (query, subquery_path, previous_results, orma_schema) => { | ||
var _a; | ||
const is_root_subquery = subquery_path.length <= 1; | ||
@@ -28,12 +29,3 @@ if (is_root_subquery) { | ||
const ancestor_result = previous_results.filter(previous_result => previous_result[0].toString() === ancestor_path.toString())[0]; | ||
if (ancestor_result === undefined || ancestor_result[1].length === 0) { | ||
// this case where there are no ancestor results can happen if, for example, this is a nested lower entitiy but | ||
// nothing was returned from the higher entitiy. In this case, we want nothing of this entity to be queried | ||
// so we use an impossible where clause that returns nothing. | ||
return { | ||
$eq: ['1', '2'], | ||
}; | ||
} | ||
const ancestor_rows = ancestor_result[1]; | ||
const ancestor_to_entity_path = subquery_path.slice(nesting_ancestor_index + 1, Infinity); | ||
const ancestor_rows = ((_a = ancestor_result === null || ancestor_result === void 0 ? void 0 : ancestor_result[1]) !== null && _a !== void 0 ? _a : []); | ||
const ancestor_where_clause = get_ancestor_where_clause(ancestor_rows, subquery_path, nesting_ancestor_index, query, orma_schema); | ||
@@ -76,3 +68,15 @@ return ancestor_where_clause; | ||
} | ||
const ancestor_foreign_key_values = ancestor_rows.map(row => row[edge_under_ancestor.from_field]); | ||
const ancestor_foreign_key_values = ancestor_rows | ||
.map(row => row[edge_under_ancestor.from_field]) | ||
// we need to filter out nulls since foreign keys can be nullable | ||
.filter(el => el !== null); | ||
if (ancestor_foreign_key_values.length === 0) { | ||
// this case where there are no ancestor results can happen if, for example, this is a nested lower entitiy but | ||
// nothing was returned from the higher entitiy. In this case, we want nothing of this entity to be queried | ||
// so we use an impossible where clause that returns nothing. We can't use a regular $where $in setup, | ||
// since that would create an sql error. | ||
return { | ||
$eq: ['1', '2'], | ||
}; | ||
} | ||
// reverse the path since we are making the where clause in the entity and want to search based on ancestor | ||
@@ -79,0 +83,0 @@ const entity_to_ancestor_edge_path = ancestor_to_entity_edge_path |
{ | ||
"name": "orma", | ||
"version": "1.0.80", | ||
"version": "1.0.81", | ||
"description": "A declarative relational syncronous orm", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -58,18 +58,7 @@ import { deep_get, last } from '../../helpers/helpers' | ||
if (ancestor_result === undefined || ancestor_result[1].length === 0) { | ||
// this case where there are no ancestor results can happen if, for example, this is a nested lower entitiy but | ||
// nothing was returned from the higher entitiy. In this case, we want nothing of this entity to be queried | ||
// so we use an impossible where clause that returns nothing. | ||
return { | ||
$eq: ['1', '2'], | ||
} | ||
} | ||
const ancestor_rows = (ancestor_result?.[1] ?? []) as Record< | ||
string, | ||
unknown | ||
>[] | ||
const ancestor_rows = ancestor_result[1] as Record<string, unknown>[] | ||
const ancestor_to_entity_path = subquery_path.slice( | ||
nesting_ancestor_index + 1, | ||
Infinity | ||
) | ||
const ancestor_where_clause = get_ancestor_where_clause( | ||
@@ -135,10 +124,21 @@ ancestor_rows, | ||
const ancestor_foreign_key_values = ancestor_rows.map( | ||
row => row[edge_under_ancestor.from_field] | ||
) | ||
const ancestor_foreign_key_values = ancestor_rows | ||
.map(row => row[edge_under_ancestor.from_field]) | ||
// we need to filter out nulls since foreign keys can be nullable | ||
.filter(el => el !== null) | ||
if (ancestor_foreign_key_values.length === 0) { | ||
// this case where there are no ancestor results can happen if, for example, this is a nested lower entitiy but | ||
// nothing was returned from the higher entitiy. In this case, we want nothing of this entity to be queried | ||
// so we use an impossible where clause that returns nothing. We can't use a regular $where $in setup, | ||
// since that would create an sql error. | ||
return { | ||
$eq: ['1', '2'], | ||
} | ||
} | ||
// reverse the path since we are making the where clause in the entity and want to search based on ancestor | ||
const entity_to_ancestor_edge_path = ancestor_to_entity_edge_path | ||
// exclude the entity closest to the ancestor, since this entity is already accounted for in the final $in clause | ||
.slice(1, Infinity) | ||
.slice(1, Infinity) | ||
// to reverse the path, we have to reverse the order of the edges but also reverse each | ||
@@ -145,0 +145,0 @@ // individual edge |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1027489
24838