Skip to content

Commit

Permalink
DeriveRelation on empty Relation enum
Browse files Browse the repository at this point in the history
  • Loading branch information
billy1624 committed Sep 8, 2022
1 parent d532deb commit dcf044f
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 65 deletions.
8 changes: 1 addition & 7 deletions examples/axum_example/entity/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ pub struct Model {
pub text: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}
8 changes: 1 addition & 7 deletions examples/graphql_example/entity/src/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ pub struct Model {
pub text: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}

impl Entity {
Expand Down
8 changes: 1 addition & 7 deletions issues/471/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ pub struct Model {
pub text: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}
8 changes: 1 addition & 7 deletions issues/630/src/entity/underscores.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,9 @@ pub struct Model {
pub aa_b_c_d: i32,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}

#[cfg(test)]
Expand Down
8 changes: 1 addition & 7 deletions issues/630/src/entity/underscores_workaround.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ pub struct Model {
pub aa_b_c_d: i32,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}

#[cfg(test)]
Expand Down
10 changes: 1 addition & 9 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,8 @@ impl EntityWriter {
let mut code_blocks = vec![
imports,
Self::gen_compact_model_struct(entity, with_serde, date_time_crate, schema_name),
Self::gen_compact_relation_enum(entity),
];
let relation_defs = if entity.get_relation_enum_name().is_empty() {
vec![
Self::gen_relation_enum(entity),
Self::gen_impl_relation_trait(entity),
]
} else {
vec![Self::gen_compact_relation_enum(entity)]
};
code_blocks.extend(relation_defs);
code_blocks.extend(Self::gen_impl_related(entity));
code_blocks.extend(Self::gen_impl_conjunct_related(entity));
code_blocks.extend(vec![Self::gen_impl_active_model_behavior()]);
Expand Down
8 changes: 1 addition & 7 deletions sea-orm-codegen/tests/compact/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ pub struct Model {
pub name: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef {
super::cake_filling::Relation::Cake.def()
Expand Down
8 changes: 1 addition & 7 deletions sea-orm-codegen/tests/compact_with_schema_name/filling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@ pub struct Model {
pub name: String,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl Related<super::cake::Entity> for Entity {
fn to() -> RelationDef {
super::cake_filling::Relation::Cake.def()
Expand Down
8 changes: 1 addition & 7 deletions src/tests_cfg/lunch_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ pub struct Model {
pub tea: Tea,
}

#[derive(Copy, Clone, Debug, EnumIter)]
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl RelationTrait for Relation {
fn def(&self) -> RelationDef {
panic!("No RelationDef")
}
}

impl ActiveModelBehavior for ActiveModel {}

0 comments on commit dcf044f

Please sign in to comment.