@joakimbugge/mikroorm-seeder / Seed
Variable: Seed
const Seed: {
(): PropertyDecorator;
(options): PropertyDecorator;
<TEntity> (factory): PropertyDecorator;
<TEntity> (factory, options): PropertyDecorator;
};Defined in: packages/mikroorm-seeder/src/seed/decorator.ts:26
MikroORM-flavoured @Seed decorator. Identical API to the base @Seed but factory callbacks receive a SeedContext that includes em.
Re-exported as a type-cast of the base implementation — zero runtime overhead.
Call Signature
(): PropertyDecorator;Marks a relation property for auto-seeding.
The related entity class is inferred from MikroORM metadata. One instance is created and recursively seeded (including its own @Seed properties).
Circular back-references are broken automatically: if the related class is already being seeded higher up in the same call chain, the property is left undefined.
Returns
PropertyDecorator
Call Signature
(options): PropertyDecorator;Marks a relation property for auto-seeding with options.
Use count on one-to-many and many-to-many properties to control how many related entities are created. Ignored for one-to-one and many-to-one.
Parameters
options
Returns
PropertyDecorator
Example
@Seed({ count: 3 })
@OneToMany(() => Film, (f) => f.director)
films!: Film[]Call Signature
<TEntity>(factory): PropertyDecorator;Marks a property with a factory callback.
The factory receives the current SeedContext and can return any value, including a Promise. Use this for scalar properties or when you need full control over how a related entity is resolved.
Type Parameters
TEntity
TEntity extends object = object
Parameters
factory
SeedFactory<unknown, TEntity>
Returns
PropertyDecorator
Examples
@Seed(() => faker.internet.email())
email!: string// Look up an existing entity instead of creating a new one
@Seed(async ({ em }) => em!.findOneOrFail(Role, { name: 'admin' }))
role!: RoleCall Signature
<TEntity>(factory, options): PropertyDecorator;Marks a property with a factory callback and additional options.
Type Parameters
TEntity
TEntity extends object = object
Parameters
factory
SeedFactory<unknown, TEntity>
options
Returns
PropertyDecorator