Struct sea_orm_migration::prelude::TableForeignKey
pub struct TableForeignKey { /* private fields */ }Expand description
Specification of a foreign key
Implementations§
§impl TableForeignKey
impl TableForeignKey
pub fn new() -> TableForeignKey
pub fn new() -> TableForeignKey
Construct a new foreign key
pub fn name<T>(&mut self, name: T) -> &mut TableForeignKeywhere
T: Into<String>,
pub fn name<T>(&mut self, name: T) -> &mut TableForeignKeywhere T: Into<String>,
Set foreign key name
pub fn from_tbl<T>(&mut self, table: T) -> &mut TableForeignKeywhere
T: IntoTableRef,
pub fn from_tbl<T>(&mut self, table: T) -> &mut TableForeignKeywhere T: IntoTableRef,
Set key table
pub fn to_tbl<R>(&mut self, ref_table: R) -> &mut TableForeignKeywhere
R: IntoTableRef,
pub fn to_tbl<R>(&mut self, ref_table: R) -> &mut TableForeignKeywhere R: IntoTableRef,
Set referencing table
pub fn from_col<T>(&mut self, column: T) -> &mut TableForeignKeywhere
T: IntoIden,
pub fn from_col<T>(&mut self, column: T) -> &mut TableForeignKeywhere T: IntoIden,
Add key column
pub fn to_col<R>(&mut self, ref_column: R) -> &mut TableForeignKeywhere
R: IntoIden,
pub fn to_col<R>(&mut self, ref_column: R) -> &mut TableForeignKeywhere R: IntoIden,
Add referencing column
pub fn on_delete(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey
pub fn on_delete(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey
Set on delete action
pub fn on_update(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey
pub fn on_update(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey
Set on update action
pub fn get_ref_table(&self) -> Option<&TableRef>
pub fn get_columns(&self) -> Vec<String, Global>
pub fn get_ref_columns(&self) -> Vec<String, Global>
pub fn get_on_delete(&self) -> Option<ForeignKeyAction>
pub fn get_on_update(&self) -> Option<ForeignKeyAction>
pub fn take(&mut self) -> TableForeignKey
Trait Implementations§
§impl Clone for TableForeignKey
impl Clone for TableForeignKey
§fn clone(&self) -> TableForeignKey
fn clone(&self) -> TableForeignKey
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read more§impl Debug for TableForeignKey
impl Debug for TableForeignKey
§impl Default for TableForeignKey
impl Default for TableForeignKey
§fn default() -> TableForeignKey
fn default() -> TableForeignKey
Returns the “default value” for a type. Read more
source§impl From<RelationDef> for TableForeignKey
impl From<RelationDef> for TableForeignKey
Creates a column definition for example to update a table.
use sea_query::{Alias, IntoIden, MysqlQueryBuilder, TableAlterStatement, TableRef};
use sea_orm::{EnumIter, Iden, Identity, PrimaryKeyTrait, RelationDef, RelationTrait, RelationType};
let relation = RelationDef {
rel_type: RelationType::HasOne,
from_tbl: TableRef::Table(Alias::new("foo").into_iden()),
to_tbl: TableRef::Table(Alias::new("bar").into_iden()),
from_col: Identity::Unary(Alias::new("bar_id").into_iden()),
to_col: Identity::Unary(Alias::new("bar_id").into_iden()),
is_owner: false,
on_delete: None,
on_update: None,
on_condition: None,
fk_name: Some("foo-bar".to_string()),
};
let mut alter_table = TableAlterStatement::new()
.table(TableRef::Table(Alias::new("foo").into_iden()))
.add_foreign_key(&mut relation.into()).take();
assert_eq!(
alter_table.to_string(MysqlQueryBuilder::default()),
"ALTER TABLE `foo` ADD CONSTRAINT `foo-bar` FOREIGN KEY (`bar_id`) REFERENCES `bar` (`bar_id`)"
);source§fn from(relation: RelationDef) -> TableForeignKey
fn from(relation: RelationDef) -> TableForeignKey
Converts to this type from the input type.