This commit is contained in:
Chris Tsang 2021-09-30 18:27:05 +08:00
parent beb3ec62dc
commit 33f0cfaa77
2 changed files with 82 additions and 0 deletions

View File

@ -139,6 +139,31 @@ async fn list(
## A quick taste of SeaORM
### Entity
```rust
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::fruit::Entity")]
Fruit,
}
impl Related<super::fruit::Entity> for Entity {
fn to() -> RelationDef {
Relation::Fruit.def()
}
}
```
### Select
```rust
// find all models

View File

@ -203,6 +203,63 @@
//!
//! ## A quick taste of SeaORM
//!
//! ### Entity
//! ```
//! # #[cfg(feature = "macros")]
//! # mod entities {
//! # 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 {
//! # #[sea_orm(
//! # belongs_to = "super::cake::Entity",
//! # from = "Column::CakeId",
//! # to = "super::cake::Column::Id"
//! # )]
//! # Cake,
//! # }
//! # impl Related<super::cake::Entity> for Entity {
//! # fn to() -> RelationDef {
//! # Relation::Cake.def()
//! # }
//! # }
//! # impl ActiveModelBehavior for ActiveModel {}
//! # }
//! # mod cake {
//! use sea_orm::entity::prelude::*;
//!
//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
//! #[sea_orm(table_name = "cake")]
//! pub struct Model {
//! #[sea_orm(primary_key)]
//! pub id: i32,
//! pub name: String,
//! }
//!
//! #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
//! pub enum Relation {
//! #[sea_orm(has_many = "super::fruit::Entity")]
//! Fruit,
//! }
//!
//! impl Related<super::fruit::Entity> for Entity {
//! fn to() -> RelationDef {
//! Relation::Fruit.def()
//! }
//! }
//! # impl ActiveModelBehavior for ActiveModel {}
//! # }
//! # }
//! ```
//!
//! ### Select
//! ```
//! # use sea_orm::{DbConn, error::*, entity::*, query::*, tests_cfg::*};