Struct sea_query::foreign_key::ForeignKeyCreateStatement [−][src]
pub struct ForeignKeyCreateStatement { /* fields omitted */ }
Expand description
Create a foreign key constraint for an existing table. Unsupported by Sqlite
Examples
use sea_query::{*, tests_cfg::*}; let foreign_key = ForeignKey::create() .name("FK_character_font") .from(Char::Table, Char::FontId) .to(Font::Table, Font::Id) .on_delete(ForeignKeyAction::Cascade) .on_update(ForeignKeyAction::Cascade) .to_owned(); assert_eq!( foreign_key.to_string(MysqlQueryBuilder), vec![ r#"ALTER TABLE `character`"#, r#"ADD CONSTRAINT `FK_character_font`"#, r#"FOREIGN KEY (`font_id`) REFERENCES `font` (`id`)"#, r#"ON DELETE CASCADE ON UPDATE CASCADE"#, ].join(" ") ); assert_eq!( foreign_key.to_string(PostgresQueryBuilder), vec![ r#"ALTER TABLE "character" ADD CONSTRAINT "FK_character_font""#, r#"FOREIGN KEY ("font_id") REFERENCES "font" ("id")"#, r#"ON DELETE CASCADE ON UPDATE CASCADE"#, ].join(" ") );
Composite key
use sea_query::{*, tests_cfg::*}; let foreign_key = ForeignKey::create() .name("FK_character_glyph") .from(Char::Table, (Char::FontId, Char::Id)) .to(Glyph::Table, (Char::FontId, Glyph::Id)) .on_delete(ForeignKeyAction::Cascade) .on_update(ForeignKeyAction::Cascade) .to_owned(); assert_eq!( foreign_key.to_string(MysqlQueryBuilder), vec![ r#"ALTER TABLE `character`"#, r#"ADD CONSTRAINT `FK_character_glyph`"#, r#"FOREIGN KEY (`font_id`, `id`) REFERENCES `glyph` (`font_id`, `id`)"#, r#"ON DELETE CASCADE ON UPDATE CASCADE"#, ].join(" ") ); assert_eq!( foreign_key.to_string(PostgresQueryBuilder), vec![ r#"ALTER TABLE "character" ADD CONSTRAINT "FK_character_glyph""#, r#"FOREIGN KEY ("font_id", "id") REFERENCES "glyph" ("font_id", "id")"#, r#"ON DELETE CASCADE ON UPDATE CASCADE"#, ].join(" ") );
Implementations
Construct a new ForeignKeyCreateStatement
pub fn table<T: 'static, R: 'static>(
&mut self,
table: T,
ref_table: R
) -> &mut Self where
T: Iden,
R: Iden,
👎 Deprecated since 0.10.2: Please use the [ForeignKeyCreateStatement::from
] and [ForeignKeyCreateStatement::to
]
pub fn table<T: 'static, R: 'static>(
&mut self,
table: T,
ref_table: R
) -> &mut Self where
T: Iden,
R: Iden,
Please use the [ForeignKeyCreateStatement::from
] and [ForeignKeyCreateStatement::to
]
Set key table and referencing table
pub fn col<T: 'static, R: 'static>(
&mut self,
column: T,
ref_column: R
) -> &mut Self where
T: Iden,
R: Iden,
👎 Deprecated since 0.10.2: Please use the [ForeignKeyCreateStatement::from
] and [ForeignKeyCreateStatement::to
]
pub fn col<T: 'static, R: 'static>(
&mut self,
column: T,
ref_column: R
) -> &mut Self where
T: Iden,
R: Iden,
Please use the [ForeignKeyCreateStatement::from
] and [ForeignKeyCreateStatement::to
]
Set key column and referencing column
Set key table and columns
Set referencing table and columns
Set referencing table
Add referencing column
Set on delete action
Set on update action
Trait Implementations
Build corresponding SQL statement for certain database backend and return SQL string
Build corresponding SQL statement for certain database backend and return SQL string
Build corresponding SQL statement for certain database backend and return SQL string
Auto Trait Implementations
impl !RefUnwindSafe for ForeignKeyCreateStatement
impl Send for ForeignKeyCreateStatement
impl Sync for ForeignKeyCreateStatement
impl Unpin for ForeignKeyCreateStatement
impl !UnwindSafe for ForeignKeyCreateStatement
Blanket Implementations
Mutably borrows from an owned value. Read more
type Output = T
type Output = T
Should always be Self