#[derive(Model)]
{
// Attributes available to this derive:
#[luxid]
}
Expand description
Derive model operations and typed columns for a SeaORM entity model.
Typed columns are the point: a column’s Value is its actual Rust type, so
a mismatched comparison is a compile error rather than a runtime surprise.
This compiles — published is an i32:
mod posts {
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, luxid::Model)]
#[sea_orm(table_name = "posts")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub published: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
let _ = posts::Model::query().where_eq(posts::Model::published, 1);This does not — a &str is not an i32:
ⓘ
mod posts {
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, luxid::Model)]
#[sea_orm(table_name = "posts")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub published: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
let _ = posts::Model::query().where_eq(posts::Model::published, "not a number");The entity’s own Column enum stays available as an untyped escape hatch,
accepting anything SeaORM would:
let _ = posts::Model::query().where_eq(posts::Column::Published, 1);Derive model operations and typed columns for a SeaORM entity model.
The model name used in 404s comes from #[sea_orm(table_name = "...")],
singularized. Override it with #[luxid(name = "Person")] when the naive
rules get it wrong.