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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzql",
3
- "version": "0.6.18",
3
+ "version": "0.6.19",
4
4
  "description": "Database-first real-time framework with TypeScript support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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 an array (one-to-many) or single (many-to-one)
141
- // For now, assume arrays unless the include key matches a FK pattern
142
- const isArray = !includeKey.endsWith('_id') && includeKey !== rootEntity;
143
- const includeType = isArray ? `${includeEntityPascal}[]` : includeEntityPascal;
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
  }