pub struct RelationDef {
pub rel_type: RelationType,
pub from_tbl: &'static str,
pub to_tbl: &'static str,
pub from_col: Vec<&'static str>,
pub to_col: Vec<&'static str>,
pub is_owner: bool,
pub on_delete: Option<ForeignKeyAction>,
pub on_update: Option<ForeignKeyAction>,
pub skip_fk: bool,
}Expand description
A relation from one entity (from) to another (to).
Fields§
§rel_type: RelationTypeThe cardinality.
from_tbl: &'static strThe table of the entity that declares the relation.
to_tbl: &'static strThe table being related to.
from_col: Vec<&'static str>The join columns on from_tbl, paired by position with to_col.
to_col: Vec<&'static str>The join columns on to_tbl, paired by position with from_col.
is_owner: boolWhether from_tbl holds the foreign key, as in belongs_to.
on_delete: Option<ForeignKeyAction>The ON DELETE action for the generated foreign key.
on_update: Option<ForeignKeyAction>The ON UPDATE action for the generated foreign key.
skip_fk: boolWhether to skip generating a foreign key for this relation.
Implementations§
Source§impl RelationDef
impl RelationDef
Sourcepub fn rev(self) -> Self
pub fn rev(self) -> Self
The reverse relation, from to back to from.
Ownership flips with the direction so that the foreign key is still attributed to the table that holds it.
Sourcepub fn join_condition(&self) -> Expr
pub fn join_condition(&self) -> Expr
Builds the join condition from.a = to.a AND from.b = to.b.
Sourcepub fn join_condition_refs(&self, from_ref: &str, to_ref: &str) -> Expr
pub fn join_condition_refs(&self, from_ref: &str, to_ref: &str) -> Expr
Builds the join condition with each side qualified by the given reference — a table name or the alias it was joined under.
Once a table is aliased, SQL requires every qualified column to use the alias, so the select builder passes the reference it chose for each side instead of the table names stored on the relation.
Sourcepub fn foreign_key(&self) -> Option<ForeignKey>
pub fn foreign_key(&self) -> Option<ForeignKey>
The foreign key this relation implies, when the declaring table owns it and generation was not skipped.
Sourcepub fn default_join(&self) -> JoinType
pub fn default_join(&self) -> JoinType
The join type find_also_related uses: LEFT, so that rows without a
related row are still returned.
Trait Implementations§
Source§impl Clone for RelationDef
impl Clone for RelationDef
Source§impl Debug for RelationDef
impl Debug for RelationDef
impl Eq for RelationDef
Source§impl<E: EntityTrait, R: EntityTrait> From<RelationBuilder<E, R>> for RelationDef
impl<E: EntityTrait, R: EntityTrait> From<RelationBuilder<E, R>> for RelationDef
Source§fn from(b: RelationBuilder<E, R>) -> Self
fn from(b: RelationBuilder<E, R>) -> Self
Source§impl PartialEq for RelationDef
impl PartialEq for RelationDef
impl StructuralPartialEq for RelationDef
Auto Trait Implementations§
impl Freeze for RelationDef
impl RefUnwindSafe for RelationDef
impl Send for RelationDef
impl Sync for RelationDef
impl Unpin for RelationDef
impl UnsafeUnpin for RelationDef
impl UnwindSafe for RelationDef
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§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.Source§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
Source§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more