Skip to main content

RelationshipInfo

Struct RelationshipInfo 

Source
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 str

Name of the relationship field.

§related_table: &'static str

The related model’s table name.

§kind: RelationshipKind

Kind 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: bool

Whether to use lazy loading (simple flag).

§cascade_delete: bool

Cascade delete behavior.

§passive_deletes: PassiveDeletes

Passive 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 list
  • Some(false): Always return a single item
  • None: Infer from field type
§related_fields_fn: fn() -> &'static [FieldInfo]

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

Source

pub const fn new( name: &'static str, related_table: &'static str, kind: RelationshipKind, ) -> Self

Create a new relationship with required fields.

Source

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.

Source

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.

Source

pub const fn related_fields(self, f: fn() -> &'static [FieldInfo]) -> Self

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.

Source

pub const fn local_key(self, key: &'static str) -> Self

Set the local foreign key column (ManyToOne).

Source

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.

Source

pub const fn remote_key(self, key: &'static str) -> Self

Set the remote foreign key column (OneToMany).

Source

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.

Set the link table metadata (ManyToMany).

Source

pub const fn back_populates(self, field: &'static str) -> Self

Set the back-populates field name (bidirectional relationships).

Source

pub const fn lazy(self, value: bool) -> Self

Enable/disable lazy loading.

Source

pub const fn cascade_delete(self, value: bool) -> Self

Enable/disable cascade delete behavior.

Source

pub const fn passive_deletes(self, value: PassiveDeletes) -> Self

Set passive delete behavior.

  • PassiveDeletes::Active (default): ORM emits DELETE for related objects
  • PassiveDeletes::Passive: Relies on DB ON DELETE CASCADE
  • PassiveDeletes::All: Passive + disables orphan tracking
Source

pub const fn order_by(self, ordering: &'static str) -> Self

Set default ordering for related items.

Source

pub const fn order_by_opt(self, ordering: Option<&'static str>) -> Self

Set default ordering from optional.

Source

pub const fn lazy_strategy(self, strategy: LazyLoadStrategy) -> Self

Set the lazy loading strategy.

Source

pub const fn lazy_strategy_opt(self, strategy: Option<LazyLoadStrategy>) -> Self

Set the lazy loading strategy from optional.

Source

pub const fn cascade(self, opts: &'static str) -> Self

Set full cascade options string.

Source

pub const fn cascade_opt(self, opts: Option<&'static str>) -> Self

Set cascade options from optional.

Source

pub const fn uselist(self, value: bool) -> Self

Force list or single.

Source

pub const fn uselist_opt(self, value: Option<bool>) -> Self

Set uselist from optional.

Source

pub const fn is_passive_deletes(&self) -> bool

Check if passive deletes are enabled (Passive or All).

Source

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

Source§

fn clone(&self) -> RelationshipInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RelationshipInfo

Source§

impl Debug for RelationshipInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RelationshipInfo

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for RelationshipInfo

Source§

impl PartialEq for RelationshipInfo

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more