Skip to content

ConstructorParams in metadata are not discovered correctly #5710

@xmajzel

Description

@xmajzel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions