pub struct TableForeignKey { /* private fields */ }
Expand description

Specification of a foreign key

Implementations§

source§

impl TableForeignKey

source

pub fn new() -> TableForeignKey

Construct a new foreign key

source

pub fn name<T>(&mut self, name: T) -> &mut TableForeignKey
where T: Into<String>,

Set foreign key name

source

pub fn from_tbl<T>(&mut self, table: T) -> &mut TableForeignKey
where T: IntoTableRef,

Set key table

source

pub fn to_tbl<R>(&mut self, ref_table: R) -> &mut TableForeignKey
where R: IntoTableRef,

Set referencing table

source

pub fn from_col<T>(&mut self, column: T) -> &mut TableForeignKey
where T: IntoIden,

Add key column

source

pub fn to_col<R>(&mut self, ref_column: R) -> &mut TableForeignKey
where R: IntoIden,

Add referencing column

source

pub fn on_delete(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey

Set on delete action

source

pub fn on_update(&mut self, action: ForeignKeyAction) -> &mut TableForeignKey

Set on update action

source

pub fn get_ref_table(&self) -> Option<&TableRef>

source

pub fn get_columns(&self) -> Vec<String>

source

pub fn get_ref_columns(&self) -> Vec<String>

source

pub fn get_on_delete(&self) -> Option<ForeignKeyAction>

source

pub fn get_on_update(&self) -> Option<ForeignKeyAction>

source

pub fn take(&mut self) -> TableForeignKey

Trait Implementations§

source§

impl Clone for TableForeignKey

source§

fn clone(&self) -> TableForeignKey

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TableForeignKey

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for TableForeignKey

source§

fn default() -> TableForeignKey

Returns the “default value” for a type. Read more
source§

impl From<RelationDef> for TableForeignKey

Creates a column definition for example to update a table.

use sea_query::{Alias, IntoIden, MysqlQueryBuilder, TableAlterStatement, TableRef, ConditionType};
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()),
    condition_type: ConditionType::All,
};

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

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more