@mikro-orm/core 6.3.14-dev.52 → 6.3.14-dev.53

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.
@@ -15,6 +15,8 @@ export interface ManyToOneOptions<Owner, Target> extends ReferenceOptions<Owner,
15
15
  joinColumn?: string;
16
16
  /** Override the default database column name on the owning side (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
17
17
  joinColumns?: string[];
18
+ /** When a part of a composite column is shared in other properties, use this option to specify what columns are considered as owned by this property. This is useful when your composite property is nullable, but parts of it are not. */
19
+ ownColumns?: string[];
18
20
  /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is only for simple properties represented by a single column. */
19
21
  referenceColumnName?: string;
20
22
  /** Override the default database column name on the target entity (see {@doclink naming-strategy | Naming Strategy}). This option is suitable for composite keys, where one property is represented by multiple columns. */
@@ -223,7 +223,7 @@ class DatabaseDriver {
223
223
  }
224
224
  if (prop.joinColumns?.length > 1 && data[k] == null) {
225
225
  delete data[k];
226
- prop.joinColumns.forEach((joinColumn, idx) => data[joinColumn] = null);
226
+ prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
227
227
  return;
228
228
  }
229
229
  if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType_1.JsonType && object) && !this.platform.isRaw(data[k])) {
@@ -31,6 +31,7 @@ export declare class MetadataDiscovery {
31
31
  private saveToCache;
32
32
  private initNullability;
33
33
  private applyNamingStrategy;
34
+ private initOwnColumns;
34
35
  private initFieldName;
35
36
  private initManyToOneFieldName;
36
37
  private initManyToManyFieldName;
@@ -361,6 +361,22 @@ class MetadataDiscovery {
361
361
  this.initOneToManyFields(prop);
362
362
  }
363
363
  }
364
+ initOwnColumns(meta) {
365
+ meta.sync();
366
+ for (const prop of meta.props) {
367
+ if (!prop.joinColumns || prop.ownColumns) {
368
+ continue;
369
+ }
370
+ if (prop.joinColumns.length > 1) {
371
+ prop.ownColumns = prop.joinColumns.filter(col => {
372
+ return !meta.props.find(p => p.name !== prop.name && (!p.fieldNames || p.fieldNames.includes(col)));
373
+ });
374
+ }
375
+ if (!prop.ownColumns || prop.ownColumns.length === 0) {
376
+ prop.ownColumns = prop.joinColumns;
377
+ }
378
+ }
379
+ }
364
380
  initFieldName(prop, object = false) {
365
381
  if (prop.fieldNames && prop.fieldNames.length > 0) {
366
382
  return;
@@ -469,6 +485,7 @@ class MetadataDiscovery {
469
485
  this.initColumnType(prop);
470
486
  this.initRelation(prop);
471
487
  }
488
+ this.initOwnColumns(meta);
472
489
  meta.simplePK = pks.length === 1 && pks[0].kind === enums_1.ReferenceKind.SCALAR && !pks[0].customType && pks[0].runtimeType !== 'Date';
473
490
  meta.serializedPrimaryKey = this.platform.getSerializedPrimaryKeyField(meta.primaryKeys[0]);
474
491
  const serializedPKProp = meta.properties[meta.serializedPrimaryKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.14-dev.52",
3
+ "version": "6.3.14-dev.53",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.3.14-dev.52",
67
+ "mikro-orm": "6.3.14-dev.53",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -365,6 +365,7 @@ export interface EntityProperty<Owner = any, Target = any> {
365
365
  pivotTable: string;
366
366
  pivotEntity: string;
367
367
  joinColumns: string[];
368
+ ownColumns: string[];
368
369
  inverseJoinColumns: string[];
369
370
  referencedColumnNames: string[];
370
371
  referencedTableName: string;