[][src]Trait diesel_factories::Factory

pub trait Factory: Clone {
    type Model;
    type Id: Clone;
    type Connection;
    fn insert(self, con: &Self::Connection) -> Self::Model;
fn id_for_model(model: &Self::Model) -> &Self::Id; }

A generic factory trait.

You shouldn't ever have to implement this trait yourself. It can be derived using #[derive(Factory)]

See the root module docs for info on how to use #[derive(Factory)].

Associated Types

type Model

The model type the factory inserts.

For a factory named UserFactory this would probably be User.

type Id: Clone

The primary key type your model uses.

This will normally be i32 or i64 but can be whatever you need.

type Connection

The database connection type you use such as diesel::pg::PgConnection.

Loading content...

Required methods

fn insert(self, con: &Self::Connection) -> Self::Model

Insert the factory into the database.

Panics

This will panic if the insert fails. Should be fine since you want panics early in tests.

fn id_for_model(model: &Self::Model) -> &Self::Id

Get the primary key value for a model type.

Just a generic wrapper around model.id.

Loading content...

Implementors

Loading content...