Skip to main content

ModelExt

Trait ModelExt 

Source
pub trait ModelExt: Model {
Show 14 methods // Required methods fn columns() -> Vec<&'static str>; fn fillable() -> Vec<&'static str>; // Provided methods fn guarded() -> Vec<&'static str> { ... } fn hidden() -> Vec<&'static str> { ... } fn visible() -> Vec<&'static str> { ... } fn casts() -> HashMap<&'static str, &'static str> { ... } fn dates() -> Vec<&'static str> { ... } fn date_format(_field: &str) -> Option<&'static str> { ... } fn relations() -> HashMap<&'static str, Relation> { ... } fn to_value(&self) -> HashMap<String, Value> { ... } fn get_column_value(&self, _column: &str) -> Option<Value> { ... } fn from_value(&mut self, _map: HashMap<String, Value>) { ... } fn fill(&mut self, map: HashMap<String, Value>) { ... } fn to_json(&self) -> Value { ... }
}
Expand description

模型扩展 trait,提供额外功能

Required Methods§

Source

fn columns() -> Vec<&'static str>

获取 SELECT 时使用的所有列

Source

fn fillable() -> Vec<&'static str>

获取可批量赋值的列(INSERT/UPDATE)

Provided Methods§

Source

fn guarded() -> Vec<&'static str>

获取受保护列(不可批量赋值)

Source

fn hidden() -> Vec<&'static str>

获取隐藏列(不参与序列化)

Source

fn visible() -> Vec<&'static str>

获取可见列(参与序列化)

Source

fn casts() -> HashMap<&'static str, &'static str>

获取类型转换映射(列名 -> 类型字符串)

Source

fn dates() -> Vec<&'static str>

获取日期列

Source

fn date_format(_field: &str) -> Option<&'static str>

获取指定字段的日期格式

Source

fn relations() -> HashMap<&'static str, Relation>

获取关系映射

Source

fn to_value(&self) -> HashMap<String, Value>

将模型转换为值映射

Source

fn get_column_value(&self, _column: &str) -> Option<Value>

获取指定列的值(须由实现重写)

Source

fn from_value(&mut self, _map: HashMap<String, Value>)

从值映射还原模型(须由实现重写)

Source

fn fill(&mut self, map: HashMap<String, Value>)

批量赋值:只填充 fillable 字段(过滤掉 guarded 字段)

Source

fn to_json(&self) -> Value

序列化为 JSON

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§