@mikro-orm/sql 7.0.17-dev.0 → 7.0.17-dev.10

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.
@@ -1676,18 +1676,19 @@ export class AbstractSqlDriver extends DatabaseDriver {
1676
1676
  });
1677
1677
  }
1678
1678
  const aliased = this.platform.quoteIdentifier(`${tableAlias}__${prop.fieldNames[0]}`);
1679
+ const sourceAlias = qb.helper.getTPTAliasForProperty(prop.name, tableAlias);
1679
1680
  if (prop.customTypes?.some(type => !!type?.convertToJSValueSQL)) {
1680
1681
  return prop.fieldNames.map((col, idx) => {
1681
1682
  if (!prop.customTypes[idx]?.convertToJSValueSQL) {
1682
1683
  return col;
1683
1684
  }
1684
- const prefixed = this.platform.quoteIdentifier(`${tableAlias}.${col}`);
1685
+ const prefixed = this.platform.quoteIdentifier(`${sourceAlias}.${col}`);
1685
1686
  const aliased = this.platform.quoteIdentifier(`${tableAlias}__${col}`);
1686
1687
  return raw(`${prop.customTypes[idx].convertToJSValueSQL(prefixed, this.platform)} as ${aliased}`);
1687
1688
  });
1688
1689
  }
1689
1690
  if (prop.customType?.convertToJSValueSQL) {
1690
- const prefixed = this.platform.quoteIdentifier(`${tableAlias}.${prop.fieldNames[0]}`);
1691
+ const prefixed = this.platform.quoteIdentifier(`${sourceAlias}.${prop.fieldNames[0]}`);
1691
1692
  return [raw(`${prop.customType.convertToJSValueSQL(prefixed, this.platform)} as ${aliased}`)];
1692
1693
  }
1693
1694
  if (prop.formula) {
@@ -1696,7 +1697,6 @@ export class AbstractSqlDriver extends DatabaseDriver {
1696
1697
  const columns = meta.createColumnMappingObject(tableAlias);
1697
1698
  return [raw(`${this.evaluateFormula(prop.formula, columns, table)} as ${aliased}`)];
1698
1699
  }
1699
- const sourceAlias = qb.helper.getTPTAliasForProperty(prop.name, tableAlias);
1700
1700
  return prop.fieldNames.map(fieldName => {
1701
1701
  return raw('?? as ??', [`${sourceAlias}.${fieldName}`, `${tableAlias}__${fieldName}`]);
1702
1702
  });
@@ -150,36 +150,34 @@ export class MySqlSchemaHelper extends SchemaHelper {
150
150
  * MySQL requires collation to be specified as an expression: (column_name COLLATE collation_name)
151
151
  */
152
152
  getIndexColumns(index) {
153
- if (index.columns?.length) {
154
- return index.columns
155
- .map(col => {
156
- const quotedName = this.quote(col.name);
157
- // MySQL supports collation via expression: (column_name COLLATE collation_name)
158
- // When collation is specified, wrap in parentheses as an expression
159
- if (col.collation) {
160
- let expr = col.length ? `${quotedName}(${col.length})` : quotedName;
161
- expr = `(${expr} collate ${col.collation})`;
162
- // Sort order comes after the expression
163
- if (col.sort) {
164
- expr += ` ${col.sort}`;
165
- }
166
- return expr;
167
- }
168
- // Standard column definition without collation
169
- let colDef = quotedName;
170
- // MySQL supports prefix length
171
- if (col.length) {
172
- colDef += `(${col.length})`;
173
- }
174
- // MySQL supports sort order
153
+ return index.columnNames
154
+ .map(name => {
155
+ const col = index.columns?.find(c => c.name === name);
156
+ const quotedName = this.quote(name);
157
+ // MySQL supports collation via expression: (column_name COLLATE collation_name)
158
+ // When collation is specified, wrap in parentheses as an expression
159
+ if (col?.collation) {
160
+ let expr = col.length ? `${quotedName}(${col.length})` : quotedName;
161
+ expr = `(${expr} collate ${col.collation})`;
162
+ // Sort order comes after the expression
175
163
  if (col.sort) {
176
- colDef += ` ${col.sort}`;
164
+ expr += ` ${col.sort}`;
177
165
  }
178
- return colDef;
179
- })
180
- .join(', ');
181
- }
182
- return index.columnNames.map(c => this.quote(c)).join(', ');
166
+ return expr;
167
+ }
168
+ // Standard column definition without collation
169
+ let colDef = quotedName;
170
+ // MySQL supports prefix length
171
+ if (col?.length) {
172
+ colDef += `(${col.length})`;
173
+ }
174
+ // MySQL supports sort order
175
+ if (col?.sort) {
176
+ colDef += ` ${col.sort}`;
177
+ }
178
+ return colDef;
179
+ })
180
+ .join(', ');
183
181
  }
184
182
  /**
185
183
  * Append MySQL-specific index suffixes like INVISIBLE.
@@ -687,27 +687,25 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
687
687
  * Build the column list for a PostgreSQL index.
688
688
  */
689
689
  getIndexColumns(index) {
690
- if (index.columns?.length) {
691
- return index.columns
692
- .map(col => {
693
- let colDef = this.quote(col.name);
694
- // PostgreSQL supports collation with double quotes
695
- if (col.collation) {
696
- colDef += ` collate ${this.quote(col.collation)}`;
697
- }
698
- // PostgreSQL supports sort order
699
- if (col.sort) {
700
- colDef += ` ${col.sort}`;
701
- }
702
- // PostgreSQL supports NULLS FIRST/LAST
703
- if (col.nulls) {
704
- colDef += ` nulls ${col.nulls}`;
705
- }
706
- return colDef;
707
- })
708
- .join(', ');
709
- }
710
- return index.columnNames.map(c => this.quote(c)).join(', ');
690
+ return index.columnNames
691
+ .map(name => {
692
+ const col = index.columns?.find(c => c.name === name);
693
+ let colDef = this.quote(name);
694
+ // PostgreSQL supports collation with double quotes
695
+ if (col?.collation) {
696
+ colDef += ` collate ${this.quote(col.collation)}`;
697
+ }
698
+ // PostgreSQL supports sort order
699
+ if (col?.sort) {
700
+ colDef += ` ${col.sort}`;
701
+ }
702
+ // PostgreSQL supports NULLS FIRST/LAST
703
+ if (col?.nulls) {
704
+ colDef += ` nulls ${col.nulls}`;
705
+ }
706
+ return colDef;
707
+ })
708
+ .join(', ');
711
709
  }
712
710
  /**
713
711
  * PostgreSQL-specific index options like fill factor.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/sql",
3
- "version": "7.0.17-dev.0",
3
+ "version": "7.0.17-dev.10",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.0.16"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.17-dev.0"
56
+ "@mikro-orm/core": "7.0.17-dev.10"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -1641,13 +1641,13 @@ export class QueryBuilder {
1641
1641
  }
1642
1642
  const types = Object.values(meta.root.discriminatorMap).map(cls => this.metadata.get(cls));
1643
1643
  const children = [];
1644
- const lookUpChildren = (ret, type) => {
1645
- const children = types.filter(meta2 => meta2.extends === type);
1646
- children.forEach(m => lookUpChildren(ret, m.class));
1644
+ const lookUpChildren = (ret, parent) => {
1645
+ const children = types.filter(meta2 => meta2.extends && this.metadata.find(meta2.extends) === parent);
1646
+ children.forEach(m => lookUpChildren(ret, m));
1647
1647
  ret.push(...children.filter(c => c.discriminatorValue));
1648
1648
  return children;
1649
1649
  };
1650
- lookUpChildren(children, meta.class);
1650
+ lookUpChildren(children, meta);
1651
1651
  this.andWhere({
1652
1652
  [meta.root.discriminatorColumn]: children.length > 0
1653
1653
  ? { $in: [meta.discriminatorValue, ...children.map(c => c.discriminatorValue)] }
@@ -132,27 +132,25 @@ export class SchemaHelper {
132
132
  * Note: Prefix length is only supported by MySQL/MariaDB which override this method.
133
133
  */
134
134
  getIndexColumns(index) {
135
- if (index.columns?.length) {
136
- return index.columns
137
- .map(col => {
138
- let colDef = this.quote(col.name);
139
- // Collation comes after column name (SQLite syntax: column COLLATE name)
140
- if (col.collation) {
141
- colDef += ` collate ${col.collation}`;
142
- }
143
- // Sort order
144
- if (col.sort) {
145
- colDef += ` ${col.sort}`;
146
- }
147
- // NULLS ordering (PostgreSQL)
148
- if (col.nulls) {
149
- colDef += ` nulls ${col.nulls}`;
150
- }
151
- return colDef;
152
- })
153
- .join(', ');
154
- }
155
- return index.columnNames.map(c => this.quote(c)).join(', ');
135
+ return index.columnNames
136
+ .map(name => {
137
+ const col = index.columns?.find(c => c.name === name);
138
+ let colDef = this.quote(name);
139
+ // Collation comes after column name (SQLite syntax: column COLLATE name)
140
+ if (col?.collation) {
141
+ colDef += ` collate ${col.collation}`;
142
+ }
143
+ // Sort order
144
+ if (col?.sort) {
145
+ colDef += ` ${col.sort}`;
146
+ }
147
+ // NULLS ordering (PostgreSQL)
148
+ if (col?.nulls) {
149
+ colDef += ` nulls ${col.nulls}`;
150
+ }
151
+ return colDef;
152
+ })
153
+ .join(', ');
156
154
  }
157
155
  /** Returns SQL to drop an index. */
158
156
  getDropIndexSQL(tableName, index) {