1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! SeaORM entity models (`entities/`).
//!
//! # Defining entities
//!
//! Database tables are SeaORM entities in `entities/` (typically one file per table):
//!
//! ```ignore
//! // entities/item.rs
//! use sea_orm::entity::prelude::*;
//!
//! #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
//! #[sea_orm(table_name = "items")]
//! pub struct Model {
//! #[sea_orm(primary_key)]
//! pub id: i64,
//! pub name: String,
//! pub created_at: chrono::DateTime<chrono::Utc>,
//! }
//!
//! #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
//! pub enum Relation {}
//!
//! impl ActiveModelBehavior for ActiveModel {}
//! ```
//!
//! Re-export from `entities/mod.rs`:
//!
//! ```ignore
//! pub mod item;
//! pub use item::Entity as ItemEntity;
//! pub use item::Model as Item;
//! ```
//!
//! # Using entities in handlers and layers
//!
//! ```ignore
//! use sea_orm::{EntityTrait, QueryOrder};
//! use super::entities::ItemEntity;
//!
//! let rows = ItemEntity::find()
//! .order_by_desc(item::Column::CreatedAt)
//! .all(&state.db)
//! .await?;
//! ```
//!
//! # Relations
//!
//! Define `Relation` enum variants for foreign keys and use `.find_also_related()`
//! or `.find_with_related()` in query patchers or loaders.
//!
//! # Migrations
//!
//! Entities describe the Rust side; schema changes go through SeaORM migrations — see
//! [`super::migrations`]. Run `cargo run -- migrate` after adding migrations.