Skip to main content

Model

Derive Macro Model 

Source
#[derive(Model)]
{
    // Attributes available to this derive:
    #[model]
}
Expand description

#[derive(Model)]. Derive Model for a struct with named fields.

#[derive(Model)]
#[model(table = "users")]
pub struct User {
    #[model(primary_key, generated)]
    pub id: i64,
    pub name: String,
    pub email: String,
    #[model(skip)]
    pub transient: Option<String>,
}

Defaults follow Laravel’s conventions: the table is the pluralised, snake_cased struct name, and a field called id is the primary key.

The generated code reaches the database package through ::rustlavel::db, since that is the dependency an application declares. A crate depending on rustlavel-db directly overrides it with #[model(crate = "rustlavel_db")].