diff --git a/docs/docs/decorators.md b/docs/docs/decorators.md index be4fc25010fb..bc9e4f3aa9ca 100644 --- a/docs/docs/decorators.md +++ b/docs/docs/decorators.md @@ -12,20 +12,19 @@ title: Decorators `@Entity` decorator is used to mark your model classes as entities. Do not use it for abstract base classes. -| Parameter | Type | Optional | Description | -|--------------------|--------------------------|----------|---------------------------------------------------------------------------------| -| `tableName` | `string` | yes | Override default collection/table name. | -| `schema` | `string` | yes | Sets the schema name | -| `collection` | `string` | yes | Alias for `tableName`. | -| `comment` | `string` | yes | Specify comment to table **(SQL only)** | -| `customRepository` | `() => EntityRepository` | yes | Set [custom repository class](repositories.md#custom-repository). | -| `discriminatorColumn` | `string` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance) | -| `discriminatorMap` | `Dictionary` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance) | -| `discriminatorValue` | `number` | `string` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance) | - -abstract | `boolean`; - -readonly | `boolean`; +| Parameter | Type | Optional | Description | +|-----------------------|--------------------------|----------|----------------------------------------------------------------------------------| +| `tableName` | `string` | yes | Override default collection/table name. | +| `schema` | `string` | yes | Sets the schema name. | +| `collection` | `string` | yes | Alias for `tableName`. | +| `comment` | `string` | yes | Specify comment to table. **(SQL only)** | +| `customRepository` | `() => EntityRepository` | yes | Set [custom repository class](repositories.md#custom-repository). | +| `discriminatorColumn` | `string` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance). | +| `discriminatorMap` | `Dictionary` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance). | +| `discriminatorValue` | `number` | `string` | yes | For [Single Table Inheritance](inheritance-mapping.md#single-table-inheritance). | +| `forceConstructor` | `boolean` | yes | Enforce use of constructor when creating managed entity instances | +| `abstract` | `boolean` | yes | Marks entity as abstract, such entities are inlined during discovery. | +| `readonly` | `boolean` | yes | Disables change tracking - such entities are ignored during flush. | ```ts diff --git a/packages/core/src/decorators/Entity.ts b/packages/core/src/decorators/Entity.ts index 9c7ae1628c7d..991fd188cc16 100644 --- a/packages/core/src/decorators/Entity.ts +++ b/packages/core/src/decorators/Entity.ts @@ -24,6 +24,7 @@ export type EntityOptions = { discriminatorColumn?: string; discriminatorMap?: Dictionary; discriminatorValue?: number | string; + forceConstructor?: boolean; comment?: string; abstract?: boolean; readonly?: boolean; diff --git a/tests/issues/GH2406.test.ts b/tests/issues/GH2406.test.ts index f2f1056d0c08..d43decb98c94 100644 --- a/tests/issues/GH2406.test.ts +++ b/tests/issues/GH2406.test.ts @@ -1,7 +1,7 @@ import { Collection, Entity, IdentifiedReference, ManyToOne, MikroORM, OneToMany, PrimaryKey } from '@mikro-orm/core'; import { SqliteDriver } from '@mikro-orm/sqlite'; -@Entity() +@Entity({ forceConstructor: true }) export class Parent { @PrimaryKey() @@ -12,7 +12,7 @@ export class Parent { } -@Entity() +@Entity({ forceConstructor: true }) export class Child { @PrimaryKey() @@ -31,7 +31,6 @@ describe('GH issue 2406', () => { orm = await MikroORM.init({ entities: [Parent, Child], dbName: ':memory:', - forceEntityConstructor: true, driver: SqliteDriver, }); await orm.schema.createSchema(); @@ -39,7 +38,7 @@ describe('GH issue 2406', () => { afterAll(() => orm.close(true)); - test('should fetch children when forceEntityConstructor is turned on', async () => { + test('should fetch children when forceConstructor is turned on', async () => { const parent = orm.em.create(Parent, {}); expect(parent.children.isInitialized()).toBe(true); expect(parent.children.isDirty()).toBe(false);