pub enum InheritanceStrategy {
None,
Single,
Joined,
Concrete,
}Expand description
Table inheritance strategy.
Determines how model hierarchies are mapped to database tables.
Variants§
None
No inheritance (default). Model is standalone.
Single
Single table inheritance: all subclasses share one table with discriminator column.
The base model specifies this strategy and the discriminator column name. Child models inherit from the base and specify their discriminator value.
Example:
#[derive(Model)]
#[sqlmodel(table, inheritance = "single", discriminator = "type")]
struct Employee { type_: String, ... }
#[derive(Model)]
#[sqlmodel(inherits = "Employee", discriminator_value = "manager")]
struct Manager { department: String, ... }Joined
Joined table inheritance: each class has its own table with FK to parent.
Base and child models each have their own table. Child tables have a foreign key column referencing the parent’s primary key. Queries join the tables.
Example:
#[derive(Model)]
#[sqlmodel(table, inheritance = "joined")]
struct Person { id: i64, name: String }
#[derive(Model)]
#[sqlmodel(table, inherits = "Person")]
struct Employee { employee_id: i64, department: String }Concrete
Concrete table inheritance: each class is independent, no DB-level inheritance.
Each model has its own complete table with all columns. There’s no database relationship between parent and child tables. Useful for shared behavior without database relationships.
Implementations§
Source§impl InheritanceStrategy
impl InheritanceStrategy
Sourcepub const fn uses_discriminator(&self) -> bool
pub const fn uses_discriminator(&self) -> bool
Check if this strategy uses a discriminator column.
Sourcepub const fn requires_join(&self) -> bool
pub const fn requires_join(&self) -> bool
Check if this strategy requires table joins for child models.
Sourcepub const fn is_inheritance(&self) -> bool
pub const fn is_inheritance(&self) -> bool
Check if this is any form of inheritance (not None).
Trait Implementations§
Source§impl Clone for InheritanceStrategy
impl Clone for InheritanceStrategy
Source§fn clone(&self) -> InheritanceStrategy
fn clone(&self) -> InheritanceStrategy
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more