Billy Chan ccb8b95324
Codegen Handle Self Referencing & Multiple Relations to the Same Related Entity (#347)
* [sea-orm-codegen] handle self referencing relation & multiple relations to the same related entity

* Test [cli]

* Test [cli]
2021-12-04 21:22:10 +08:00

65 lines
1.4 KiB
Rust

//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "rust_keyword")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub testing: i32,
pub rust: i32,
pub keywords: i32,
pub r#type: i32,
pub r#typeof: i32,
pub crate_: i32,
pub self_: i32,
pub self_id1: i32,
pub self_id2: i32,
pub fruit_id1: i32,
pub fruit_id2: i32,
pub cake_id: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "Entity",
from = "Column::SelfId1",
to = "Column::Id",
)]
SelfRef1,
#[sea_orm(
belongs_to = "Entity",
from = "Column::SelfId2",
to = "Column::Id",
)]
SelfRef2,
#[sea_orm(
belongs_to = "super::fruit::Entity",
from = "Column::FruitId1",
to = "super::fruit::Column::Id",
)]
Fruit1,
#[sea_orm(
belongs_to = "super::fruit::Entity",
from = "Column::FruitId2",
to = "super::fruit::Column::Id",
)]
Fruit2,
#[sea_orm(
belongs_to = "super::cake::Entity",
from = "Column::CakeId",
to = "super::cake::Column::Id",
)]
Cake,
}
impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef {
Relation::Cake.def()
}
}
impl ActiveModelBehavior for ActiveModel {}