MikroORM strategy
Map MikroORM 6 entities with entity, reference, and collection serialization built into the classes strategy.
@automapper/mikro extends the classes strategy for MikroORM 6.
npm install @automapper/core @automapper/classes @automapper/mikro reflect-metadatapnpm add @automapper/core @automapper/classes @automapper/mikro reflect-metadatabun add @automapper/core @automapper/classes @automapper/mikro reflect-metadataconst mapper = createMapper({
strategyInitializer: mikro(),
});
Use @AutoMap() metadata and register mappings exactly as with classes(). The default preMap recursively serializes MikroORM entities, references, and collections before member mapping begins.
Override strategy behavior when your entity lifecycle needs it:
const mapper = createMapper({
strategyInitializer: mikro({
preMap: (source, mapping) => customSerialize(source, mapping),
destinationConstructor: (_, destinationIdentifier) =>
entityManager.create(destinationIdentifier, {}),
}),
});
Supplying preMap replaces MikroORM’s default serialization hook, so the custom implementation is responsible for producing a mappable source shape.