Search code examples
node.jsnestjsmikro-orm

MikroORM Eager is set to false yet the relation is still being loaded


I have the following entity:

@Entity()
export class SomeEntity extends BaseEntity implements ISomeEntity {
@ManyToOne(() => OtherEntity, {
    nullable: true,
    eager: false
  })
  otherEntity: OtherEntity;
}

But otherEntity is still loaded when running findOne or find functions.

I don't know how to stop loading other relations without affecting where conditions. As this leads to circular issues.

Based on the decorators here https://mikro-orm.io/docs/decorators/#manytoone

eager boolean yes Always load the relationship.


Solution

  • Apparently in MikroORM, it links any relation that was previously loaded automatically regardless the eagerness. This is by design as per documentation.