pub struct RelationshipInfo {Show 17 fields
pub name: &'static str,
pub related_table: &'static str,
pub kind: RelationshipKind,
pub local_key: Option<&'static str>,
pub local_keys: Option<&'static [&'static str]>,
pub remote_key: Option<&'static str>,
pub remote_keys: Option<&'static [&'static str]>,
pub link_table: Option<LinkTableInfo>,
pub back_populates: Option<&'static str>,
pub lazy: bool,
pub cascade_delete: bool,
pub passive_deletes: PassiveDeletes,
pub order_by: Option<&'static str>,
pub lazy_strategy: Option<LazyLoadStrategy>,
pub cascade: Option<&'static str>,
pub uselist: Option<bool>,
pub related_fields_fn: fn() -> &'static [FieldInfo],
}Expand description
Metadata about a relationship between models.
Fields§
§name: &'static strName of the relationship field.
The related model’s table name.
kind: RelationshipKindKind of relationship.
local_key: Option<&'static str>Local foreign key column (for ManyToOne).
e.g., "team_id" on Hero.
local_keys: Option<&'static [&'static str]>Composite local foreign key columns (for ManyToOne).
If set, this takes precedence over local_key.
remote_key: Option<&'static str>Remote foreign key column (for OneToMany).
e.g., "team_id" on Hero when accessed from Team.
remote_keys: Option<&'static [&'static str]>Composite remote foreign key columns (for OneToMany / OneToOne).
If set, this takes precedence over remote_key.
link_table: Option<LinkTableInfo>Link table for ManyToMany relationships.
back_populates: Option<&'static str>The field on the related model that points back.
lazy: boolWhether to use lazy loading (simple flag).
cascade_delete: boolCascade delete behavior.
passive_deletes: PassiveDeletesPassive delete behavior - whether ORM emits DELETE or relies on DB cascade.
order_by: Option<&'static str>Default ordering for related items (e.g., “name”, “created_at DESC”).
lazy_strategy: Option<LazyLoadStrategy>Loading strategy for this relationship.
cascade: Option<&'static str>Full cascade options string (e.g., “all, delete-orphan”).
uselist: Option<bool>Force list or single (override field type inference).
Some(true): Always return a listSome(false): Always return a single itemNone: Infer from field type
Function pointer returning the related model’s fields metadata.
This keeps relationship metadata “zero-cost” (static + no allocation) while still letting higher layers (query builder, eager loaders) build stable projections for related models without runtime reflection.
Implementations§
Source§impl RelationshipInfo
impl RelationshipInfo
Sourcepub const fn new(
name: &'static str,
related_table: &'static str,
kind: RelationshipKind,
) -> Self
pub const fn new( name: &'static str, related_table: &'static str, kind: RelationshipKind, ) -> Self
Create a new relationship with required fields.
Sourcepub fn local_key_cols(&self) -> &[&'static str]
pub fn local_key_cols(&self) -> &[&'static str]
Return the local key columns for this relationship (empty slice if unset).
For single-column relationships, this returns a 1-element slice backed by self.local_key.
Sourcepub fn remote_key_cols(&self) -> &[&'static str]
pub fn remote_key_cols(&self) -> &[&'static str]
Return the remote key columns for this relationship (empty slice if unset).
For single-column relationships, this returns a 1-element slice backed by self.remote_key.
Provide the related model’s Model::fields() function pointer.
Derive macros should set this for relationship fields so query builders can project and alias the related columns deterministically.
Sourcepub const fn local_key(self, key: &'static str) -> Self
pub const fn local_key(self, key: &'static str) -> Self
Set the local foreign key column (ManyToOne).
Sourcepub const fn local_keys(self, keys: &'static [&'static str]) -> Self
pub const fn local_keys(self, keys: &'static [&'static str]) -> Self
Set composite local foreign key columns (ManyToOne).
The column order must match the parent primary key value ordering.
Sourcepub const fn remote_key(self, key: &'static str) -> Self
pub const fn remote_key(self, key: &'static str) -> Self
Set the remote foreign key column (OneToMany).
Sourcepub const fn remote_keys(self, keys: &'static [&'static str]) -> Self
pub const fn remote_keys(self, keys: &'static [&'static str]) -> Self
Set composite remote foreign key columns (OneToMany / OneToOne).
The column order must match the parent primary key value ordering.
Sourcepub const fn link_table(self, info: LinkTableInfo) -> Self
pub const fn link_table(self, info: LinkTableInfo) -> Self
Set the link table metadata (ManyToMany).
Sourcepub const fn back_populates(self, field: &'static str) -> Self
pub const fn back_populates(self, field: &'static str) -> Self
Set the back-populates field name (bidirectional relationships).
Sourcepub const fn cascade_delete(self, value: bool) -> Self
pub const fn cascade_delete(self, value: bool) -> Self
Enable/disable cascade delete behavior.
Sourcepub const fn passive_deletes(self, value: PassiveDeletes) -> Self
pub const fn passive_deletes(self, value: PassiveDeletes) -> Self
Set passive delete behavior.
PassiveDeletes::Active(default): ORM emits DELETE for related objectsPassiveDeletes::Passive: Relies on DB ON DELETE CASCADEPassiveDeletes::All: Passive + disables orphan tracking
Sourcepub const fn order_by(self, ordering: &'static str) -> Self
pub const fn order_by(self, ordering: &'static str) -> Self
Set default ordering for related items.
Sourcepub const fn order_by_opt(self, ordering: Option<&'static str>) -> Self
pub const fn order_by_opt(self, ordering: Option<&'static str>) -> Self
Set default ordering from optional.
Sourcepub const fn lazy_strategy(self, strategy: LazyLoadStrategy) -> Self
pub const fn lazy_strategy(self, strategy: LazyLoadStrategy) -> Self
Set the lazy loading strategy.
Sourcepub const fn lazy_strategy_opt(self, strategy: Option<LazyLoadStrategy>) -> Self
pub const fn lazy_strategy_opt(self, strategy: Option<LazyLoadStrategy>) -> Self
Set the lazy loading strategy from optional.
Sourcepub const fn cascade_opt(self, opts: Option<&'static str>) -> Self
pub const fn cascade_opt(self, opts: Option<&'static str>) -> Self
Set cascade options from optional.
Sourcepub const fn uselist_opt(self, value: Option<bool>) -> Self
pub const fn uselist_opt(self, value: Option<bool>) -> Self
Set uselist from optional.
Sourcepub const fn is_passive_deletes(&self) -> bool
pub const fn is_passive_deletes(&self) -> bool
Check if passive deletes are enabled (Passive or All).
Sourcepub const fn is_passive_deletes_all(&self) -> bool
pub const fn is_passive_deletes_all(&self) -> bool
Check if orphan tracking is disabled (passive_deletes=‘all’).
Trait Implementations§
Source§impl Clone for RelationshipInfo
impl Clone for RelationshipInfo
Source§fn clone(&self) -> RelationshipInfo
fn clone(&self) -> RelationshipInfo
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for RelationshipInfo
Source§impl Debug for RelationshipInfo
impl Debug for RelationshipInfo
Source§impl Default for RelationshipInfo
impl Default for RelationshipInfo
impl Eq for RelationshipInfo
Auto Trait Implementations§
impl Freeze for RelationshipInfo
impl RefUnwindSafe for RelationshipInfo
impl Send for RelationshipInfo
impl Sync for RelationshipInfo
impl Unpin for RelationshipInfo
impl UnsafeUnpin for RelationshipInfo
impl UnwindSafe for RelationshipInfo
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.