-
-
Notifications
You must be signed in to change notification settings - Fork 610
Closed
Description
Describe the bug
ConstructorParams are not discovered correctly, when using default value for parameter inside constructor.
For entity UserConstructorWithDefault, discovered constructorParams are ["data", Symbol(ObjectBindingPattern)], instead of just ["data"] (correctly discovered for UserConstructorWithoutDefault entity).
Reproduction
import {
MikroORM,
Entity,
PrimaryKey,
EntityData,
} from '@mikro-orm/sqlite';
@Entity()
class UserConstructorWithDefault {
@PrimaryKey()
readonly id!: bigint;
constructor(data: EntityData<UserConstructorWithDefault> = {}) {
Object.assign(this, data);
}
}
@Entity()
class UserConstructorWithoutDefault {
@PrimaryKey()
readonly id!: bigint;
constructor(data?: EntityData<UserConstructorWithoutDefault>) {
Object.assign(this, data ?? {});
}
}
let orm: MikroORM;
beforeAll(async () => {
orm = await MikroORM.init({
entities: [UserConstructorWithoutDefault, UserConstructorWithDefault],
dbName: ':memory:',
});
await orm.schema.createSchema();
});
afterAll(async () => {
await orm.schema.dropSchema();
await orm.close(true);
});
test('correctly discover constructorParams', async () => {
expect(orm.em.getMetadata(UserConstructorWithoutDefault).constructorParams).toEqual(['data']);
expect(orm.em.getMetadata(UserConstructorWithDefault).constructorParams).toEqual(['data']);
});What driver are you using?
None
MikroORM version
6.2.9
Node.js version
20.11.1
Operating system
Mac OS Sonoma 14.4.1 (23E224)
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Slack.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
No labels