Skip to main content

BelongsTo

Trait BelongsTo 

Source
pub trait BelongsTo<P>:
    Entity
    + Clone
    + Send
    + Sync
where P: Entity + Debug + Send + Sync,
{ // Required methods fn foreign_key() -> &'static str; fn foreign_key_value(&self) -> Option<String>; // Provided method fn relation_meta() -> RelationMeta { ... } }
Expand description

Trait for BelongsTo relationships (child-to-parent)

A BelongsTo relationship exists when the child entity contains a foreign key that references the parent entity.

§Example

use ormkit::relations::BelongsTo;

// Post belongs to User
impl BelongsTo<User> for Post {
    fn foreign_key() -> &'static str {
        "user_id"
    }
}

Required Methods§

Source

fn foreign_key() -> &'static str

The foreign key column name on this entity

This is the column that stores the ID of the parent entity

Source

fn foreign_key_value(&self) -> Option<String>

Get the foreign key value from this entity

§Returns

The ID of the parent entity, or None if not set

Provided Methods§

Source

fn relation_meta() -> RelationMeta

Get relation metadata

§Returns

Metadata about this relationship

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§