@mikro-orm/core 7.1.15-dev.15 → 7.1.15-dev.16

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": "@mikro-orm/core",
3
- "version": "7.1.15-dev.15",
3
+ "version": "7.1.15-dev.16",
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",
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.1.15-dev.15';
156
+ static #ORM_VERSION = '7.1.15-dev.16';
157
157
  /**
158
158
  * Checks if the argument is instance of `Object`. Returns false for arrays.
159
159
  */
@@ -138,7 +138,14 @@ function getPropertyValue(obj, key) {
138
138
  }
139
139
  /** @internal */
140
140
  export function getWhereCondition(meta, onConflictFields, data, where) {
141
- const unique = onConflictFields ?? meta.props.filter(p => p.unique).map(p => p.name);
141
+ // TPT children do not inherit the unique flags and indexes of their parent tables
142
+ const uniqueProps = new Set();
143
+ const uniques = [];
144
+ for (let current = meta; current; current = current.tptParent) {
145
+ current.props.filter(p => p.unique).forEach(p => uniqueProps.add(p.name));
146
+ uniques.push(...current.uniques);
147
+ }
148
+ const unique = onConflictFields ?? [...uniqueProps];
142
149
  const propIndex = !isRaw(unique) &&
143
150
  unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
144
151
  if (onConflictFields || where == null) {
@@ -152,8 +159,8 @@ export function getWhereCondition(meta, onConflictFields, data, where) {
152
159
  }
153
160
  where = { [key]: getPropertyValue(data, unique[propIndex]) };
154
161
  }
155
- else if (meta.uniques.length > 0) {
156
- for (const u of meta.uniques) {
162
+ else {
163
+ for (const u of uniques) {
157
164
  if (Utils.asArray(u.properties).every(p => data[p] != null)) {
158
165
  where = Utils.asArray(u.properties).reduce((o, key) => {
159
166
  o[key] = data[key];