@joakimbugge/mikroorm-seeder / Seed
Function: Seed()
Call Signature
function Seed(): PropertyDecorator;Defined in: seed/decorator.ts:13
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
function Seed(options): PropertyDecorator;Defined in: seed/decorator.ts:25
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
function Seed<TEntity>(factory): PropertyDecorator;Defined in: seed/decorator.ts:42
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 = any
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
function Seed<TEntity>(factory, options): PropertyDecorator;Defined in: seed/decorator.ts:44
Marks a property with a factory callback and additional options.
Type Parameters
TEntity
TEntity = any
Parameters
factory
SeedFactory<unknown, TEntity>
options
Returns
PropertyDecorator