pub struct RelationSpec {
pub name: String,
pub relation_type: RelationType,
pub related_model: String,
pub related_table: String,
pub fields: Vec<String>,
pub references: Vec<String>,
pub join_table: Option<JoinTableSpec>,
pub on_delete: Option<ReferentialAction>,
pub on_update: Option<ReferentialAction>,
}Expand description
Specification for a relation between models.
Fields§
§name: StringName of the relation (field name).
relation_type: RelationTypeType of relation.
Name of the related model.
Name of the related table.
fields: Vec<String>Foreign key fields on this model.
references: Vec<String>Referenced fields on the related model.
join_table: Option<JoinTableSpec>Join table for many-to-many relations.
on_delete: Option<ReferentialAction>On delete action.
on_update: Option<ReferentialAction>On update action.
Implementations§
Source§impl RelationSpec
impl RelationSpec
Sourcepub fn one_to_one(
name: impl Into<String>,
related_model: impl Into<String>,
related_table: impl Into<String>,
) -> Self
pub fn one_to_one( name: impl Into<String>, related_model: impl Into<String>, related_table: impl Into<String>, ) -> Self
Create a one-to-one relation spec.
Sourcepub fn one_to_many(
name: impl Into<String>,
related_model: impl Into<String>,
related_table: impl Into<String>,
) -> Self
pub fn one_to_many( name: impl Into<String>, related_model: impl Into<String>, related_table: impl Into<String>, ) -> Self
Create a one-to-many relation spec.
Sourcepub fn many_to_one(
name: impl Into<String>,
related_model: impl Into<String>,
related_table: impl Into<String>,
) -> Self
pub fn many_to_one( name: impl Into<String>, related_model: impl Into<String>, related_table: impl Into<String>, ) -> Self
Create a many-to-one relation spec.
Sourcepub fn many_to_many(
name: impl Into<String>,
related_model: impl Into<String>,
related_table: impl Into<String>,
join_table: JoinTableSpec,
) -> Self
pub fn many_to_many( name: impl Into<String>, related_model: impl Into<String>, related_table: impl Into<String>, join_table: JoinTableSpec, ) -> Self
Create a many-to-many relation spec.
Sourcepub fn fields(self, fields: impl IntoIterator<Item = impl Into<String>>) -> Self
pub fn fields(self, fields: impl IntoIterator<Item = impl Into<String>>) -> Self
Set the foreign key fields.
Sourcepub fn references(
self,
refs: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn references( self, refs: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set the referenced fields.
Sourcepub fn to_join_clause(&self, parent_alias: &str, child_alias: &str) -> String
pub fn to_join_clause(&self, parent_alias: &str, child_alias: &str) -> String
Generate the JOIN clause for this relation.
Trait Implementations§
Source§impl Clone for RelationSpec
impl Clone for RelationSpec
Source§fn clone(&self) -> RelationSpec
fn clone(&self) -> RelationSpec
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RelationSpec
impl RefUnwindSafe for RelationSpec
impl Send for RelationSpec
impl Sync for RelationSpec
impl Unpin for RelationSpec
impl UnwindSafe for RelationSpec
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)