@mikro-orm/entity-generator 6.4.3-dev.0 → 6.4.3-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.
@@ -65,11 +65,11 @@ class EntityGenerator {
65
65
  .map(table => {
66
66
  const skipColumns = options.skipColumns?.[table.getShortestName()];
67
67
  if (skipColumns) {
68
- table.getColumns().forEach(col => {
68
+ for (const col of table.getColumns()) {
69
69
  if (skipColumns.some(matchColumnName => this.matchName(col.name, matchColumnName))) {
70
70
  table.removeColumn(col.name);
71
71
  }
72
- });
72
+ }
73
73
  }
74
74
  return table.getEntityDeclaration(this.namingStrategy, this.helper, options.scalarPropertiesForRelations);
75
75
  });
@@ -82,6 +82,13 @@ class EntityGenerator {
82
82
  prop.runtimeType = (runtimeTypes.length === 1 ? runtimeTypes[0] : `[${runtimeTypes.join(', ')}]`);
83
83
  prop.type = mappedTypes.length === 1 ? (core_1.Utils.entries(core_1.types).find(([k, v]) => Object.getPrototypeOf(mappedTypes[0]) === v.prototype)?.[0] ?? mappedTypes[0].name) : 'unknown';
84
84
  }
85
+ const meta2 = metadata.find(meta2 => meta2.className === prop.type);
86
+ const targetPrimaryColumns = meta2?.getPrimaryProps().flatMap(p => p.fieldNames);
87
+ if (targetPrimaryColumns && targetPrimaryColumns.length !== prop.referencedColumnNames.length) {
88
+ prop.ownColumns = prop.joinColumns.filter(col => {
89
+ return !meta.props.find(p => p.name !== prop.name && (!p.fieldNames || p.fieldNames.includes(col)));
90
+ });
91
+ }
85
92
  }
86
93
  }
87
94
  await options.onInitialMetadata?.(metadata, this.platform);
@@ -90,11 +97,13 @@ class EntityGenerator {
90
97
  for (const duplicate of duplicates) {
91
98
  for (const meta of metadata.filter(meta => meta.className === duplicate)) {
92
99
  meta.className = this.namingStrategy.getEntityName(`${meta.schema ?? schema.name}_${meta.className}`);
93
- metadata.forEach(relMeta => relMeta.relations.forEach(prop => {
94
- if (prop.type === duplicate && (prop.referencedTableName === meta.collection || prop.referencedTableName === `${meta.schema ?? schema.name}.${meta.collection}`)) {
95
- prop.type = meta.className;
100
+ for (const relMeta of metadata) {
101
+ for (const prop of relMeta.relations) {
102
+ if (prop.type === duplicate && (prop.referencedTableName === meta.collection || prop.referencedTableName === `${meta.schema ?? schema.name}.${meta.collection}`)) {
103
+ prop.type = meta.className;
104
+ }
96
105
  }
97
- }));
106
+ }
98
107
  }
99
108
  }
100
109
  this.detectManyToManyRelations(metadata, options.onlyPurePivotTables, options.readOnlyPivotTables, options.outputPurePivotTables);
package/README.md CHANGED
@@ -299,13 +299,13 @@ Or if you want to use UUID primary keys:
299
299
  **`./entities/UuidBook.ts`**
300
300
 
301
301
  ```typescript
302
- import { v4 } from 'uuid';
302
+ import { randomUUID } from 'node:crypto';
303
303
 
304
304
  @Entity()
305
305
  export class UuidBook {
306
306
 
307
307
  @PrimaryKey()
308
- uuid = v4();
308
+ uuid = randomUUID();
309
309
 
310
310
  }
311
311
  ```
package/SourceFile.js CHANGED
@@ -692,6 +692,9 @@ class SourceFile {
692
692
  options.fieldNames = prop.fieldNames.map(fieldName => this.quote(fieldName));
693
693
  }
694
694
  }
695
+ if (prop.ownColumns && prop.ownColumns.length !== prop.fieldNames.length) {
696
+ options.referencedColumnNames = prop.referencedColumnNames.map(fieldName => this.quote(fieldName));
697
+ }
695
698
  if (!['no action', 'restrict'].includes(prop.updateRule.toLowerCase())) {
696
699
  options.updateRule = this.quote(prop.updateRule);
697
700
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/entity-generator",
3
- "version": "6.4.3-dev.0",
3
+ "version": "6.4.3-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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -58,13 +58,13 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "6.4.3-dev.0",
61
+ "@mikro-orm/knex": "6.4.3-dev.10",
62
62
  "fs-extra": "11.2.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@mikro-orm/core": "^6.4.2"
66
66
  },
67
67
  "peerDependencies": {
68
- "@mikro-orm/core": "6.4.3-dev.0"
68
+ "@mikro-orm/core": "6.4.3-dev.10"
69
69
  }
70
70
  }