dzql 0.6.18 → 0.6.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/cli/codegen/types.ts +8 -4
package/package.json
CHANGED
package/src/cli/codegen/types.ts
CHANGED
|
@@ -133,14 +133,18 @@ export type FilterValue<T> = T | FilterOperators<T>;
|
|
|
133
133
|
|
|
134
134
|
// Add includes as optional fields
|
|
135
135
|
if (sub.includes) {
|
|
136
|
+
const rootEntityIR = entities[rootEntity];
|
|
137
|
+
const rootColumns = new Set(rootEntityIR.columns.map(c => c.name));
|
|
138
|
+
|
|
136
139
|
for (const [includeKey, includeIR] of Object.entries(sub.includes)) {
|
|
137
140
|
const includeEntity = includeIR.entity;
|
|
138
141
|
const includeEntityPascal = toPascalCase(includeEntity);
|
|
139
142
|
|
|
140
|
-
// Determine if it's
|
|
141
|
-
//
|
|
142
|
-
const
|
|
143
|
-
const
|
|
143
|
+
// Determine if it's many-to-one (singular) or one-to-many (array)
|
|
144
|
+
// If root entity has a column `{includeKey}_id`, it's many-to-one
|
|
145
|
+
const fkColumn = `${includeKey}_id`;
|
|
146
|
+
const isManyToOne = rootColumns.has(fkColumn);
|
|
147
|
+
const includeType = isManyToOne ? includeEntityPascal : `${includeEntityPascal}[]`;
|
|
144
148
|
|
|
145
149
|
output += ` ${includeKey}?: ${includeType};\n`;
|
|
146
150
|
}
|