-
-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codegen: testing entity generation of composite foreign key (#2071)
- Loading branch information
Showing
9 changed files
with
494 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "child")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub parent_id1: i32, | ||
pub parent_id2: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::parent::Entity", | ||
from = "(Column::ParentId1, Column::ParentId2)", | ||
to = "(super::parent::Column::Id1, super::parent::Column::Id2)", | ||
)] | ||
Parent, | ||
} | ||
|
||
impl Related<super::parent::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Parent.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(table_name = "parent")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id1: i32, | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id2: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm(has_many = "super::child::Entity")] | ||
Child, | ||
} | ||
|
||
impl Related<super::child::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Child.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(schema_name = "schema_name", table_name = "child")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub parent_id1: i32, | ||
pub parent_id2: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm( | ||
belongs_to = "super::parent::Entity", | ||
from = "(Column::ParentId1, Column::ParentId2)", | ||
to = "(super::parent::Column::Id1, super::parent::Column::Id2)", | ||
)] | ||
Parent, | ||
} | ||
|
||
impl Related<super::parent::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Parent.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.1.0 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] | ||
#[sea_orm(schema_name = "schema_name", table_name = "parent")] | ||
pub struct Model { | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id1: i32, | ||
#[sea_orm(primary_key, auto_increment = false)] | ||
pub id2: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm(has_many = "super::child::Entity")] | ||
Child, | ||
} | ||
|
||
impl Related<super::child::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Child.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//! SeaORM Entity. Generated by sea-orm-codegen 0.10.0 | ||
use sea_orm::entity::prelude::*; | ||
|
||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)] | ||
pub struct Entity; | ||
|
||
impl EntityName for Entity { | ||
fn table_name(&self) -> &str { | ||
"child" | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveModel, DeriveActiveModel, Eq)] | ||
pub struct Model { | ||
pub id: i32, | ||
pub parent_id1: i32, | ||
pub parent_id2: i32, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)] | ||
pub enum Column { | ||
Id, | ||
ParentId1, | ||
ParentId2, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)] | ||
pub enum PrimaryKey { | ||
Id, | ||
} | ||
|
||
impl PrimaryKeyTrait for PrimaryKey { | ||
type ValueType = i32; | ||
fn auto_increment() -> bool { | ||
true | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter)] | ||
pub enum Relation { | ||
Parent, | ||
} | ||
|
||
impl ColumnTrait for Column { | ||
type EntityName = Entity; | ||
fn def(&self) -> ColumnDef { | ||
match self { | ||
Self::Id => ColumnType::Integer.def(), | ||
Self::ParentId1 => ColumnType::Integer.def(), | ||
Self::ParentId2 => ColumnType::Integer.def(), | ||
} | ||
} | ||
} | ||
|
||
impl RelationTrait for Relation { | ||
fn def(&self) -> RelationDef { | ||
match self { | ||
Self::Parent => Entity::belongs_to(super::parent::Entity) | ||
.from((Column::ParentId1, Column::ParentId2)) | ||
.to((super::parent::Column::Id1, super::parent::Column::Id2)) | ||
.into(), | ||
} | ||
} | ||
} | ||
|
||
impl Related<super::parent::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Parent.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
Oops, something went wrong.