It works, pfew

This commit is contained in:
rijkvanzanten
2020-07-14 18:48:21 -04:00
parent dd6c7043ac
commit a5620b8b37
2 changed files with 36 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
import { AST, NestedCollectionAST } from '../types/ast';
import { uniq, pick } from 'lodash';
import { clone, uniq, pick } from 'lodash';
import database, { schemaInspector } from './index';
import { Filter, Query } from '../types';
import { QueryBuilder } from 'knex';
@@ -138,9 +138,13 @@ export default async function runAST(ast: AST, query = ast.query) {
results = results.map((record) => {
if (m2o) {
const nestedResult =
nestedResults.find((nestedRecord) => {
return nestedRecord[batch.relation.primary_one] === record[batch.fieldKey];
}) || null;
clone(
nestedResults.find((nestedRecord) => {
return (
nestedRecord[batch.relation.primary_one] === record[batch.fieldKey]
);
})
) || null;
if (tempField && nestedResult) {
delete nestedResult[tempField];