Skip to main content

toasty_core/schema/app/
embedded.rs

1use crate::{
2    schema::{app::ModelId, db},
3    stmt,
4};
5
6/// A reference to an embedded model (struct or enum) that is stored inline
7/// within its parent model's table rather than in a separate table.
8///
9/// Embedded fields are flattened into the parent table's columns at the
10/// database level, but appear as nested types at the application level.
11///
12/// # Examples
13///
14/// ```ignore
15/// use toasty_core::schema::app::Embedded;
16///
17/// // Embedded is typically constructed by the schema builder.
18/// let embedded: &Embedded = embedded_field;
19/// let target_model = schema.model(embedded.target);
20/// ```
21#[derive(Debug, Clone)]
22pub struct Embedded {
23    /// The [`ModelId`] of the embedded model being referenced.
24    pub target: ModelId,
25
26    /// The expression type of this embedded field from the application's
27    /// perspective.
28    pub expr_ty: stmt::Type,
29
30    /// Optional database type override for an embedded enum's discriminant
31    /// column. Embedded structs do not accept a type override because they may
32    /// map to more than one column.
33    pub storage_ty: Option<db::Type>,
34}