Skip to content

Expose on_delete and on_update for ForeignKey fields #540

@ElijahAhianyo

Description

@ElijahAhianyo

We currently have these policies defined

cot/cot/src/db/relations.rs

Lines 143 to 154 in 4620c6a

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub enum ForeignKeyOnDeletePolicy {
/// Don't do any additional actions on delete.
NoAction,
/// Prevent the delete if this model instance is referenced by another row.
#[default]
Restrict,
/// Remove the referencing row if the referenced row is deleted.
Cascade,
/// Set the foreign key in the referencing row to [`None`].
SetNone,
}
and

cot/cot/src/db/relations.rs

Lines 175 to 187 in 4620c6a

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub enum ForeignKeyOnUpdatePolicy {
/// Don't do any additional actions on update.
NoAction,
/// Prevent the update if this model instance is referenced by another row.
Restrict,
/// Update the foreign key in the referencing row if the referenced row is
/// updated.
#[default]
Cascade,
/// Set the foreign key in the referencing row to [`None`].
SetNone,
}

However, we need to be able to expose them. Perhaps to use them like this:

#[model]
struct Foo {
   #[model(on_delete="cascade", on_update="set_none")]
   bar: ForeignKey<Bar>
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-libCrate: cot (main library crate)enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions