pub struct Relationship {
pub table: QualifiedIdentifier,
pub foreign_table: QualifiedIdentifier,
pub is_self: bool,
pub cardinality: Cardinality,
pub table_is_view: bool,
pub foreign_table_is_view: bool,
}Expand description
Foreign key relationship between two tables
Represents the relationship from one table to another via a foreign key constraint.
Fields§
§table: QualifiedIdentifierSource table (the table containing the FK columns)
foreign_table: QualifiedIdentifierTarget table (the table being referenced)
is_self: boolWhether this is a self-referencing relationship
cardinality: CardinalityRelationship cardinality (M2O, O2M, O2O, M2M)
table_is_view: boolWhether the source table is a view
foreign_table_is_view: boolWhether the target table is a view
Implementations§
Source§impl Relationship
impl Relationship
Sourcepub fn is_to_one(&self) -> bool
pub fn is_to_one(&self) -> bool
Check if this is a to-one relationship (M2O or O2O)
Returns true if following this relationship yields at most one row.
Sourcepub fn is_to_many(&self) -> bool
pub fn is_to_many(&self) -> bool
Check if this is a to-many relationship (O2M or M2M)
Sourcepub fn constraint_name(&self) -> &str
pub fn constraint_name(&self) -> &str
Get the constraint name for this relationship
Sourcepub fn columns(&self) -> &[(CompactString, CompactString)]
pub fn columns(&self) -> &[(CompactString, CompactString)]
Get the column mappings for this relationship
Returns pairs of (source_column, target_column).
Sourcepub fn source_columns(&self) -> impl Iterator<Item = &str>
pub fn source_columns(&self) -> impl Iterator<Item = &str>
Get the source column names
Sourcepub fn target_columns(&self) -> impl Iterator<Item = &str>
pub fn target_columns(&self) -> impl Iterator<Item = &str>
Get the target column names
Sourcepub fn uses_column(&self, col_name: &str) -> bool
pub fn uses_column(&self, col_name: &str) -> bool
Check if this relationship uses a specific column
Sourcepub fn junction(&self) -> Option<&Junction>
pub fn junction(&self) -> Option<&Junction>
Get the junction table if this is an M2M relationship
Sourcepub fn reverse(&self) -> Self
pub fn reverse(&self) -> Self
Create the reverse direction of this relationship.
Swaps table / foreign_table and flips cardinality:
- M2O → O2M (and vice-versa)
- O2O child → O2O parent (and vice-versa)
Column pairs are swapped so (src, tgt) becomes (tgt, src).
Sourcepub fn is_o2o_parent(&self) -> bool
pub fn is_o2o_parent(&self) -> bool
Check if this is an O2O relationship where we are the parent side
Sourcepub fn is_o2o_child(&self) -> bool
pub fn is_o2o_child(&self) -> bool
Check if this is an O2O relationship where we are the child side
Trait Implementations§
Source§impl Clone for Relationship
impl Clone for Relationship
Source§fn clone(&self) -> Relationship
fn clone(&self) -> Relationship
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more