pub trait HasFactory: Sized {
type Factory: Factory<Self>;
// Provided method
fn factory() -> FactoryBuilder<Self, Self::Factory> { ... }
}Expand description
Bind a model to its factory. Mirrors Laravel’s convention of Database\Factories\UserFactory
being associated with App\Models\User.
Implement on the model:
ⓘ
impl HasFactory for User {
type Factory = UserFactory;
}Then User::factory().count(50).create(&c).await? works.
Required Associated Types§
Provided Methods§
fn factory() -> FactoryBuilder<Self, Self::Factory>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.