pub trait ActiveRecord:
Model
+ ModelExt
+ RelationLoader
+ Clone
+ Send
+ Sync {
// Provided methods
fn with(self, relation: &str) -> WithRelation<Self> { ... }
fn with_all(self, relations: Vec<&str>) -> WithRelation<Self> { ... }
}Expand description
支持关系加载的模型 trait(ActiveRecord 模式)
L-5 修复:补充示例文档
§示例
ⓘ
use sz_orm_model::model::{Model, ActiveRecord};
#[derive(Debug, Clone, Default)]
struct User { id: i64, name: String }
impl Model for User {
type PrimaryKey = i64;
fn table_name() -> &'static str { "users" }
fn pk(&self) -> Self::PrimaryKey { self.id }
fn set_pk(&mut self, pk: Self::PrimaryKey) { self.id = pk; }
}
// 假设已实现 ModelExt + RelationLoader
impl ActiveRecord for User {}
// 通过 with() 链式预加载多个关系
let user = User { id: 1, name: "Alice".into() }
.with("orders")
.with("profile");Provided Methods§
Sourcefn with(self, relation: &str) -> WithRelation<Self>
fn with(self, relation: &str) -> WithRelation<Self>
预加载指定关系
用法:user.with("orders").with("profile").load(&mut conn).await
Sourcefn with_all(self, relations: Vec<&str>) -> WithRelation<Self>
fn with_all(self, relations: Vec<&str>) -> WithRelation<Self>
一次性预加载多个关系
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".