@ronin/compiler 0.10.0-leo-ron-1083-experimental-207 → 0.10.1-leo-ron-1083-experimental-208
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +31 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1212,6 +1212,11 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1212
1212
|
if (symbol?.type === "query") {
|
1213
1213
|
let { queryModel: subQueryModelSlug, queryInstructions: subQueryInstructions } = splitQuery(symbol.value);
|
1214
1214
|
const subQueryModel = getModelBySlug(models, subQueryModelSlug);
|
1215
|
+
if (subQueryInstructions?.selecting) {
|
1216
|
+
const currentFields = new Set(subQueryInstructions.selecting);
|
1217
|
+
currentFields.add("id");
|
1218
|
+
subQueryInstructions.selecting = Array.from(currentFields);
|
1219
|
+
}
|
1215
1220
|
const subQuerySelectedFields = subQueryInstructions?.selecting;
|
1216
1221
|
const subQueryIncludedFields = subQueryInstructions?.including;
|
1217
1222
|
const subQueryFields = [
|
@@ -1234,7 +1239,19 @@ var handleTo = (models, model, statementParams, queryType, dependencyStatements,
|
|
1234
1239
|
...subQueryInstructions.including
|
1235
1240
|
};
|
1236
1241
|
}
|
1237
|
-
|
1242
|
+
let statement2 = "";
|
1243
|
+
if (subQuerySelectedFields) {
|
1244
|
+
const selectedFields = [
|
1245
|
+
...subQueryFields,
|
1246
|
+
...defaultFieldsToAdd.map(([key]) => key)
|
1247
|
+
];
|
1248
|
+
const columns = selectedFields.map((field) => {
|
1249
|
+
return getFieldFromModel(model, field, "to").fieldSelector;
|
1250
|
+
});
|
1251
|
+
statement2 = `(${columns.join(", ")}) `;
|
1252
|
+
}
|
1253
|
+
statement2 += compileQueryInput(symbol.value, models, statementParams).main.statement;
|
1254
|
+
return statement2;
|
1238
1255
|
}
|
1239
1256
|
Object.assign(toInstruction, defaultFields);
|
1240
1257
|
for (const fieldSlug in toInstruction) {
|
@@ -1498,11 +1515,22 @@ var Transaction = class {
|
|
1498
1515
|
return expand(formattedRecord);
|
1499
1516
|
}
|
1500
1517
|
prepareResults(results) {
|
1501
|
-
|
1518
|
+
const relevantResults = results.filter((_, index) => {
|
1519
|
+
return this.statements[index].returning;
|
1520
|
+
});
|
1521
|
+
return relevantResults.map((result, index) => {
|
1502
1522
|
const query = this.queries.at(-index);
|
1503
1523
|
const { queryModel } = splitQuery(query);
|
1504
1524
|
const model = getModelBySlug(this.models, queryModel);
|
1505
|
-
|
1525
|
+
const single = queryModel !== model.pluralSlug;
|
1526
|
+
if (single) {
|
1527
|
+
return { record: this.formatRecord(model, result[0]) };
|
1528
|
+
}
|
1529
|
+
return {
|
1530
|
+
records: result.map((resultItem) => {
|
1531
|
+
return this.formatRecord(model, resultItem);
|
1532
|
+
})
|
1533
|
+
};
|
1506
1534
|
});
|
1507
1535
|
}
|
1508
1536
|
};
|
package/package.json
CHANGED