Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model_extra_derives to be also added to coresponding enums #1392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sea-orm-codegen/src/entity/active_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ActiveEnum {
}

impl ActiveEnum {
pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool) -> TokenStream {
pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool, mut extra_derive: TokenStream) -> TokenStream {
let enum_name = &self.enum_name.to_string();
let enum_iden = format_ident!("{}", enum_name.to_camel_case());
let values: Vec<String> = self.values.iter().map(|v| v.to_string()).collect();
Expand All @@ -24,7 +24,8 @@ impl ActiveEnum {
}
});

let extra_derive = with_serde.extra_derive();
extra_derive.extend(with_serde.extra_derive());

let copy_derive = if with_copy_enums {
quote! { , Copy }
} else {
Expand Down Expand Up @@ -72,7 +73,7 @@ mod tests {
.map(|variant| Alias::new(variant).into_iden())
.collect(),
}
.impl_active_enum(&WithSerde::None, true)
.impl_active_enum(&WithSerde::None, true, quote!(""))
.to_string(),
quote!(
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy)]
Expand Down Expand Up @@ -105,4 +106,4 @@ mod tests {
.to_string()
)
}
}
}
13 changes: 7 additions & 6 deletions sea-orm-codegen/src/entity/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl EntityWriter {
files.push(self.write_prelude());
if !self.enums.is_empty() {
files.push(
self.write_sea_orm_active_enums(&context.with_serde, context.with_copy_enums),
self.write_sea_orm_active_enums(context),
);
}
WriterOutput { files }
Expand Down Expand Up @@ -277,17 +277,18 @@ impl EntityWriter {

pub fn write_sea_orm_active_enums(
&self,
with_serde: &WithSerde,
with_copy_enums: bool,
context: &EntityWriterContext
) -> OutputFile {
let mut lines = Vec::new();
Self::write_doc_comment(&mut lines);
Self::write(&mut lines, vec![Self::gen_import(with_serde)]);
Self::write(&mut lines, vec![Self::gen_import(&context.with_serde)]);
lines.push("".to_owned());


let code_blocks = self
.enums
.values()
.map(|active_enum| active_enum.impl_active_enum(with_serde, with_copy_enums))
.map(|active_enum| active_enum.impl_active_enum(&context.with_serde, context.with_copy_enums, context.model_extra_derives.clone()))
.collect();
Self::write(&mut lines, code_blocks);
OutputFile {
Expand Down Expand Up @@ -1957,4 +1958,4 @@ mod tests {

Ok(expected.to_string())
}
}
}