pub struct FactoryBuilder<T: Factory> { /* private fields */ }Expand description
Builder for creating model instances with customizations
Implementations§
Source§impl<T: Factory> FactoryBuilder<T>
impl<T: Factory> FactoryBuilder<T>
Sourcepub fn set<V, F>(self, value: V, setter: F) -> Self
pub fn set<V, F>(self, value: V, setter: F) -> Self
Set a field value using a setter function
This is useful for setting foreign keys when creating associated models. The value is cloned for each model when creating multiple instances.
§Example
ⓘ
// Create a user first, then create posts belonging to that user
let user = User::factory().create().await?;
let post = Post::factory()
.set(user.id, |p, user_id| p.user_id = user_id)
.create()
.await?;
// Create multiple posts for the same user
let posts = Post::factory()
.count(5)
.set(user.id, |p, user_id| p.user_id = user_id)
.create_many()
.await?;Sourcepub fn after_make<F>(self, f: F) -> Self
pub fn after_make<F>(self, f: F) -> Self
Sourcepub fn after_create<F, Fut>(self, f: F) -> Self
pub fn after_create<F, Fut>(self, f: F) -> Self
Source§impl<T: DatabaseFactory> FactoryBuilder<T>
impl<T: DatabaseFactory> FactoryBuilder<T>
Sourcepub async fn create(self) -> Result<T, FrameworkError>
pub async fn create(self) -> Result<T, FrameworkError>
Sourcepub async fn create_many(self) -> Result<Vec<T>, FrameworkError>
pub async fn create_many(self) -> Result<Vec<T>, FrameworkError>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for FactoryBuilder<T>
impl<T> !RefUnwindSafe for FactoryBuilder<T>
impl<T> Send for FactoryBuilder<T>
impl<T> !Sync for FactoryBuilder<T>
impl<T> Unpin for FactoryBuilder<T>
impl<T> UnsafeUnpin for FactoryBuilder<T>
impl<T> !UnwindSafe for FactoryBuilder<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more