pub trait IntoActiveModel<A>where
A: ActiveModelTrait,{
// Required method
fn into_active_model(self) -> A;
}Expand description
A Trait for any type that can be converted into an ActiveModel,
can be derived using DeriveIntoActiveModel.
ยงDerive Macro Example
use sea_orm::DeriveIntoActiveModel;
mod fruit {
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "fruit")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub cake_id: Option<i32>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
}
#[derive(DeriveIntoActiveModel)]
#[sea_orm(active_model = "fruit::ActiveModel")]
struct NewFruit {
name: String,
// `id` and `cake_id` are omitted - they become `NotSet`
}ยงset(...) - always set absent ActiveModel fields
use sea_orm::DeriveIntoActiveModel;
#[derive(DeriveIntoActiveModel)]
#[sea_orm(active_model = "fruit::ActiveModel", set(cake_id = "None"))]
struct NewFruit {
name: String,
// `cake_id` is not on the struct, but will always be `Set(None)`
}ยงdefault = "expr" - fallback for Option<T> struct fields
use sea_orm::DeriveIntoActiveModel;
#[derive(DeriveIntoActiveModel)]
#[sea_orm(active_model = "fruit::ActiveModel")]
struct UpdateFruit {
/// `Some("Apple")` -> `Set("Apple")`, `None` ->`Set("Unnamed")`
#[sea_orm(default = "String::from(\"Unnamed\")")]
name: Option<String>,
}Required Methodsยง
Sourcefn into_active_model(self) -> A
fn into_active_model(self) -> A
Method to call to perform the conversion
Implementorsยง
impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::permission::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::resource::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::role::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::role_hierarchy::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::role_permission::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::user_override::Model
Available on crate feature
rbac only.impl IntoActiveModel<ActiveModel> for sea_orm::rbac::entity::user_role::Model
Available on crate feature
rbac only.