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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! Entities and the types and traits that describe them.
//!
//! In SeaORM, every database table is represented by an **Entity** — a unit
//! struct implementing [`EntityTrait`]. The Entity ties together:
//!
//! - the table's **name** (via [`EntityName`]),
//! - its **columns** (via [`ColumnTrait`] and the strongly-typed `COLUMN` constant),
//! - its **primary key** (via [`PrimaryKeyTrait`] / [`PrimaryKeyToColumn`]),
//! - its **relations** to other entities (via [`RelationTrait`]; in 2.0,
//! relations can also be declared directly on the `Model` struct as
//! [`HasOne`](compound::HasOne) / [`HasMany`](compound::HasMany) fields).
//!
//! Each Entity has two companion types:
//!
//! - **[`Model`](ModelTrait)** — a plain struct mirroring a row of the table,
//! used for reads.
//! - **[`ActiveModel`](ActiveModelTrait)** — a struct where every field is
//! wrapped in [`ActiveValue`], used for inserts and partial updates.
//!
//! From an Entity you can build select, insert, update, and delete queries
//! via [`EntityTrait::find`], [`EntityTrait::insert`], [`EntityTrait::update`],
//! and [`EntityTrait::delete`] (plus their `_many` / `_by_id` siblings).
//!
//! # Defining an Entity (2.0 dense format)
//!
//! The recommended way to define an entity in SeaORM 2.0 is the dense entity
//! format, where the relations live directly on the `Model` struct as
//! [`HasOne`](compound::HasOne) / [`HasMany`](compound::HasMany) fields:
//!
//! ```
//! # #[cfg(feature = "macros")]
//! # mod entities {
//! # mod fruit {
//! # use sea_orm::entity::prelude::*;
//! # #[sea_orm::model]
//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
//! # #[sea_orm(table_name = "fruit")]
//! # pub struct Model {
//! # #[sea_orm(primary_key)]
//! # pub id: i32,
//! # pub cake_id: Option<i32>,
//! # #[sea_orm(belongs_to, from = "cake_id", to = "id")]
//! # pub cake: HasOne<super::cake::Entity>,
//! # }
//! # impl ActiveModelBehavior for ActiveModel {}
//! # }
//! mod cake {
//! use sea_orm::entity::prelude::*;
//!
//! #[sea_orm::model]
//! #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
//! #[sea_orm(table_name = "cake")]
//! pub struct Model {
//! #[sea_orm(primary_key)]
//! pub id: i32,
//! pub name: String,
//! #[sea_orm(has_many)]
//! pub fruits: HasMany<super::fruit::Entity>,
//! }
//!
//! impl ActiveModelBehavior for ActiveModel {}
//! }
//! # }
//! ```
//!
//! # Defining an Entity (1.0 compact format)
//!
//! The 1.0 compact format remains supported. Here relations are declared as a
//! separate `Relation` enum implementing [`RelationTrait`], plus an explicit
//! [`Related`] impl per foreign entity:
//!
//! ```
//! # #[cfg(feature = "macros")]
//! # mod entities {
//! # mod fruit {
//! # use sea_orm::entity::prelude::*;
//! # #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
//! # #[sea_orm(table_name = "fruit")]
//! # pub struct Model {
//! # #[sea_orm(primary_key)]
//! # pub id: i32,
//! # 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, Eq, 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 {}
//! }
//! # }
//! ```
//!
//! Entity files are usually generated for you with `sea-orm-cli` against an
//! existing database. See the [crate-level documentation](crate) for a
//! walkthrough of the most common operations.
pub
/// Re-exports the types and traits most commonly needed to define and use
/// entities. Glob-import this module in entity files: `use sea_orm::entity::prelude::*;`.
pub
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use EntityLoaderTrait;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;