Skip to main content

ManyToMany

Trait ManyToMany 

Source
pub trait ManyToMany<T: Entity>: Entity {
    // Required methods
    fn join_table() -> &'static str;
    fn local_key() -> &'static str;
    fn foreign_key() -> &'static str;
}
Expand description

多对多关系 trait

定义实体之间的多对多关系

§Example

struct User {
    id: i64,
    roles: Vec<Role>,
}

struct Role {
    id: i64,
    users: Vec<User>,
}

impl ManyToMany<Role> for User {
    fn join_table() -> &'static str {
        "user_roles"
    }

    fn local_key() -> &'static str {
        "user_id"
    }

    fn foreign_key() -> &'static str {
        "role_id"
    }
}

Required Methods§

Source

fn join_table() -> &'static str

中间表名

Source

fn local_key() -> &'static str

本地键列名(中间表中指向当前表的列名)

Source

fn foreign_key() -> &'static str

外键列名(中间表中指向关联表的列名)

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§