Skip to content

Commit e702c49

Browse files
Merge pull request #1822 from exogee-technology/fix/introspection-of-entities-with-only-single-primary-key
Fix / Introspection of entities with only single primary key
2 parents 2761aa7 + 734f3f0 commit e702c49

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/packages/mikroorm/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"reflect-metadata": "0.2.2"
3737
},
3838
"peerDependencies": {
39-
"graphql": "16",
4039
"@mikro-orm/core": "6",
41-
"@mikro-orm/knex": "6"
40+
"@mikro-orm/knex": "6",
41+
"graphql": "16"
4242
},
4343
"devDependencies": {
4444
"@mikro-orm/core": "6.4.16",

src/packages/mikroorm/src/introspection/files/schema-entity-file.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
Platform,
77
} from '@mikro-orm/core';
88
import { ReferenceKind, Utils } from '@mikro-orm/core';
9-
109
import pluralize from 'pluralize';
1110
import { identifierForEnumValue, pascalToCamelCaseString, pascalToKebabCaseString } from '../utils';
1211
import { BaseFile } from './base-file';
@@ -103,7 +102,18 @@ export class SchemaEntityFile extends BaseFile {
103102
}
104103

105104
this.coreImports.add('Entity');
106-
file += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {\n\tprovider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}' }),\n})\n`;
105+
106+
file += `@Entity<${this.meta.className}>(${this.quote(this.meta.className)}, {\n\tprovider: new MikroBackendProvider(Orm${this.meta.className}, connection, { backendDisplayName: '${friendlyNameForDatabaseType(this.databaseType)}'})`;
107+
108+
if (props.length === 1 && props[0].primary) {
109+
// Special case. If there's a single primary key field in this entity, right now that requires that it's a client side generated primary key.
110+
// There's no reason this has to be the case, but it's a current limitation, so we should generate a working project for them.
111+
// We should be able to remove this in the future and allow users to use it both ways.
112+
file += `,\n\tapiOptions: { clientGeneratedPrimaryKeys: true },\n})\n`;
113+
} else {
114+
file += `\n})\n`;
115+
}
116+
107117
file += `export class ${this.meta.className} {\n`;
108118
file += `${classBody}}\n`;
109119
const imports = [

0 commit comments

Comments
 (0)