Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary embeddable-related collections when ensureIndexes flag set to true #1040

Closed
cherfia opened this issue Nov 5, 2020 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@cherfia
Copy link
Contributor

cherfia commented Nov 5, 2020

Describe the bug
MikroORM creates unnecessary embeddable-related collections when it gets initialized with ensureIndexes set to true.

To Reproduce
Steps to reproduce the behavior in Nestjs framework:

  1. Create an embeddable class
@Embeddable()
export class Address {
  
  @Property()
  street!: string;

  @Property()
  postalCode!: string;

  @Property()
  city!: string;

  @Property()
  country!: string;

}
  1. Create an entity class which uses the above embeddable class to define one of its properties
@Entity({ collection: 'users' })
export class User {

  @Embedded()
  address!: Address;

}
  1. Setup MikroORM configuration and enable ensureIndexes option
MikroOrmModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        type: 'mongo',
        ensureIndexes: true,
        entities: [Address, User],
      }),
    }),

Running NestJS with such a configuration will result in generating two collections: users and address

Expected behavior
MikroORM should filter out embeddable classes from the entities array when it gets initialized. In other words, in our example, MikroORM should create only one single collection (i.e. users).

Versions

Dependency Version
node 14.8.0
typescript 3.7.4
mikro-orm 4.2.3
@mikro-orm/mongodb 4.2.3
@B4nan B4nan added the bug Something isn't working label Nov 5, 2020
@B4nan B4nan closed this as completed in a0cc877 Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants