From 3581cedfb1a67e8c8eddc4d9748ae9c1cc59e7f0 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 20:33:15 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=F0=9F=8E=A8=20add=20`field=5Fattr=5Fcont?= =?UTF-8?q?ain=5Fkey`=20to=20find=20special=20attr=20arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/derives/util.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sea-orm-macros/src/derives/util.rs b/sea-orm-macros/src/derives/util.rs index 7de4b79cd..32ba8894e 100644 --- a/sea-orm-macros/src/derives/util.rs +++ b/sea-orm-macros/src/derives/util.rs @@ -3,6 +3,10 @@ use quote::format_ident; use syn::{punctuated::Punctuated, token::Comma, Field, Ident, Meta}; pub(crate) fn field_not_ignored(field: &Field) -> bool { + !field_attr_contain_key(field, "ignore") +} + +pub(crate) fn field_attr_contain_key(field: &Field, key: &'static str) -> bool { for attr in field.attrs.iter() { if let Some(ident) = attr.path.get_ident() { if ident != "sea_orm" { @@ -16,15 +20,15 @@ pub(crate) fn field_not_ignored(field: &Field) -> bool { for meta in list.iter() { if let Meta::Path(path) = meta { if let Some(name) = path.get_ident() { - if name == "ignore" { - return false; + if name == key { + return true; } } } } } } - true + false } pub(crate) fn format_field_ident(field: Field) -> Ident { From 424c6dc17b8f4755ad3656a8ab4f0d31e2d4beb9 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 20:46:08 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E2=9C=A8=20make=20`FromQueryResult`=20su?= =?UTF-8?q?pport=20`flatten`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/derives/from_query_result.rs | 44 ++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index 999db62fe..d6aa8aad1 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -1,6 +1,24 @@ use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote, quote_spanned}; -use syn::{ext::IdentExt, Data, DataStruct, Field, Fields, Generics}; +use syn::{ext::IdentExt, Data, DataStruct, Field, Fields, Generics, Type}; + +use super::util::field_attr_contain_key; + +struct FieldInfo { + ident: Ident, + flatten: bool, + ty: Type, +} + +impl From for FieldInfo { + fn from(value: Field) -> Self { + Self { + flatten: field_attr_contain_key(&value, "flatten"), + ident: format_ident!("{}", value.ident.unwrap().to_string()), + ty: value.ty, + } + } +} /// Method to derive a [QueryResult](sea_orm::QueryResult) pub fn expand_derive_from_query_result( @@ -8,6 +26,9 @@ pub fn expand_derive_from_query_result( data: Data, generics: Generics, ) -> syn::Result { + let arg_row = &format_ident!("row"); + let arg_pre = &format_ident!("pre"); + let fields = match data { Data::Struct(DataStruct { fields: Fields::Named(named), @@ -20,16 +41,17 @@ pub fn expand_derive_from_query_result( } }; - let field: Vec = fields - .into_iter() - .map(|Field { ident, .. }| format_ident!("{}", ident.unwrap().to_string())) - .collect(); + let field: Vec = fields.into_iter().map(FieldInfo::from).collect(); - let name: Vec = field + let field_query: Vec = field .iter() - .map(|f| { - let s = f.unraw().to_string(); - quote! { #s } + .map(|FieldInfo { ident, flatten, ty }| { + let s = ident.unraw().to_string(); + if *flatten{ + quote! { #ident : <#ty as sea_orm::FromQueryResult>::from_query_result(#arg_row, #arg_pre)? } + }else{ + quote! { #ident : #arg_row.try_get(#arg_pre, #s)?} + } }) .collect(); @@ -38,9 +60,9 @@ pub fn expand_derive_from_query_result( Ok(quote!( #[automatically_derived] impl #impl_generics sea_orm::FromQueryResult for #ident #ty_generics #where_clause { - fn from_query_result(row: &sea_orm::QueryResult, pre: &str) -> std::result::Result { + fn from_query_result(#arg_row: &sea_orm::QueryResult, #arg_pre: &str) -> std::result::Result { Ok(Self { - #(#field: row.try_get(pre, #name)?),* + #(#field_query),* }) } } From 1dd75778af838803ec75cb25620eefb49be05fd2 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 20:57:30 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E2=9C=A8=20make=20`partial=5Fmodel`=20ca?= =?UTF-8?q?n=20flatten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/derives/partial_model.rs | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/sea-orm-macros/src/derives/partial_model.rs b/sea-orm-macros/src/derives/partial_model.rs index 3d3703582..084a8852e 100644 --- a/sea-orm-macros/src/derives/partial_model.rs +++ b/sea-orm-macros/src/derives/partial_model.rs @@ -13,12 +13,15 @@ use syn::Meta; use self::util::GetAsKVMeta; +use super::util::field_attr_contain_key; + #[derive(Debug)] enum Error { InputNotStruct, EntityNotSpecific, NotSupportGeneric(Span), BothFromColAndFromExpr(Span), + FlattenNotOnly(Span), Syn(syn::Error), } #[derive(Debug, PartialEq, Eq)] @@ -29,6 +32,8 @@ enum ColumnAs { ColAlias { col: syn::Ident, field: String }, /// from a expr Expr { expr: syn::Expr, field_name: String }, + /// flatten + Flatten { ty: syn::Type }, } struct DerivePartialModel { @@ -75,6 +80,7 @@ impl DerivePartialModel { let mut from_col = None; let mut from_expr = None; + let flatten = field_attr_contain_key(&field, "flatten"); for attr in field.attrs.iter() { if !attr.path.is_ident("sea_orm") { @@ -97,8 +103,8 @@ impl DerivePartialModel { let field_name = field.ident.unwrap(); - let col_as = match (from_col, from_expr) { - (None, None) => { + let col_as = match (from_col, from_expr, flatten) { + (None, None, false) => { if entity_ident.is_none() { return Err(Error::EntityNotSpecific); } @@ -107,11 +113,11 @@ impl DerivePartialModel { field_name.to_string().to_upper_camel_case() )) } - (None, Some(expr)) => ColumnAs::Expr { + (None, Some(expr), false) => ColumnAs::Expr { expr, field_name: field_name.to_string(), }, - (Some(col), None) => { + (Some(col), None, false) => { if entity_ident.is_none() { return Err(Error::EntityNotSpecific); } @@ -119,7 +125,11 @@ impl DerivePartialModel { let field = field_name.to_string(); ColumnAs::ColAlias { col, field } } - (Some(_), Some(_)) => return Err(Error::BothFromColAndFromExpr(field_span)), + (None, None, true) => ColumnAs::Flatten { ty: field.ty }, + (Some(_), _, true) | (_, Some(_), true) => { + return Err(Error::FlattenNotOnly(field_span)) + } + (Some(_), Some(_), _) => return Err(Error::BothFromColAndFromExpr(field_span)), }; column_as_list.push(col_as); } @@ -156,6 +166,9 @@ impl DerivePartialModel { ColumnAs::Expr { expr, field_name } => { quote!(let #select_ident = sea_orm::SelectColumns::select_column_as(#select_ident, #expr, #field_name);) }, + ColumnAs::Flatten { ty }=>{ + quote!(let #select_ident = <#ty as sea_orm::PartialModelTrait>::select_cols(#select_ident);) + } }); quote! { @@ -187,6 +200,9 @@ pub fn expand_derive_partial_model(input: syn::DeriveInput) -> syn::Result Ok(quote_spanned! { ident_span => compile_error!("you can only derive `DerivePartialModel` on named struct"); }), + Err(Error::FlattenNotOnly(span)) => Ok(quote_spanned! { + span => compile_error!("you can only derive `DerivePartialModel` on named struct"); + }), Err(Error::Syn(err)) => Err(err), } } From 820b36cf73dcba9756acfdb57e4d263304639971 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 21:01:30 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E2=9E=95=20update=20`FromQueryResult`=20?= =?UTF-8?q?document?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index 0e9c7b1b8..f7c0a6aab 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -590,6 +590,24 @@ pub fn derive_active_enum(input: TokenStream) -> TokenStream { /// num_of_fruits: i32, /// } /// ``` +/// +/// Can contain other `FromQueryResult` for a complex query result +/// ``` +/// use sea_orm::{entity::prelude::*, FromQueryResult}; +/// +/// #[derive(Debug, FromQueryResult)] +/// struct Foo{ +/// bar: i64 +/// } +/// +/// #[derive(Debug, FromQueryResult)] +/// struct SelectResult { +/// name: String, +/// num_of_fruits: i32, +/// #[sea_orm(flatten)] +/// foo: Foo +/// } +/// ``` #[cfg(feature = "derive")] #[proc_macro_derive(FromQueryResult)] pub fn derive_from_query_result(input: TokenStream) -> TokenStream { From 3fed10c1160c1297fa25726de64e13c4552d0195 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 21:09:02 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=F0=9F=93=9D=20add=20`DerivePartialModel`?= =?UTF-8?q?=20document=20for=20`flatten`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/lib.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index f7c0a6aab..0d6d5faa5 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -799,6 +799,44 @@ pub fn derive_from_json_query_result(input: TokenStream) -> TokenStream { /// sum: i32 /// } /// ``` +/// +/// Can contain orther `PartialModel` for complex col constitution +/// ``` +/// use sea_orm::{entity::prelude::*, sea_query::Expr, DerivePartialModel, FromQueryResult}; +/// +/// #[derive(Debug, FromQueryResult, DerivePartialModel)] +/// struct SelectResult { +/// #[sea_orm(from_expr = "Expr::val(1).add(1)")] +/// sum: i32, +/// #[sea_orm(flatten)] +/// foo: Foo +/// } +/// +/// #[derive(Debug, FromQueryResult, DerivePartialModel)] +/// struct Foo{ +/// #[sea_orm(from_expr = "Expr::val(12).add(2)")] +/// bar: i64 +/// } +/// ``` +/// Note: the `flatten` cannot use with `from_expr` or `from_col`, +/// or is cannot compile +/// ```compile_fail +/// use sea_orm::{entity::prelude::*, sea_query::Expr, DerivePartialModel, FromQueryResult}; +/// +/// #[derive(Debug, FromQueryResult, DerivePartialModel)] +/// struct SelectResult { +/// #[sea_orm(from_expr = "Expr::val(1).add(1)")] +/// sum: i32, +/// #[sea_orm(flatten, from_expr = "Expr::val(11).div(5)")] +/// foo: Foo +/// } +/// +/// #[derive(Debug, FromQueryResult, DerivePartialModel)] +/// struct Foo{ +/// #[sea_orm(from_expr = "Expr::val(12).add(2)")] +/// bar: i64 +/// } +/// ``` #[cfg(feature = "derive")] #[proc_macro_derive(DerivePartialModel, attributes(sea_orm))] pub fn derive_partial_model(input: TokenStream) -> TokenStream { From a7ad402befa0d93218e3ac2c88059e62f3f21329 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 21:10:04 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=F0=9F=9A=A8=20FromQueryResult=20has=20at?= =?UTF-8?q?tributes=20sea=5Form?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index 0d6d5faa5..d98d3dc6e 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -609,7 +609,7 @@ pub fn derive_active_enum(input: TokenStream) -> TokenStream { /// } /// ``` #[cfg(feature = "derive")] -#[proc_macro_derive(FromQueryResult)] +#[proc_macro_derive(FromQueryResult, attributes(sea_orm))] pub fn derive_from_query_result(input: TokenStream) -> TokenStream { let DeriveInput { ident, From 9df21b773c0d6bdc9ce4b38416d6c7956c1f1200 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 21:10:37 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=F0=9F=8E=A8=20cargo=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sea-orm-macros/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sea-orm-macros/src/lib.rs b/sea-orm-macros/src/lib.rs index d98d3dc6e..477fc14fd 100644 --- a/sea-orm-macros/src/lib.rs +++ b/sea-orm-macros/src/lib.rs @@ -596,8 +596,8 @@ pub fn derive_active_enum(input: TokenStream) -> TokenStream { /// use sea_orm::{entity::prelude::*, FromQueryResult}; /// /// #[derive(Debug, FromQueryResult)] -/// struct Foo{ -/// bar: i64 +/// struct Foo { +/// bar: i64, /// } /// /// #[derive(Debug, FromQueryResult)] @@ -605,7 +605,7 @@ pub fn derive_active_enum(input: TokenStream) -> TokenStream { /// name: String, /// num_of_fruits: i32, /// #[sea_orm(flatten)] -/// foo: Foo +/// foo: Foo, /// } /// ``` #[cfg(feature = "derive")] @@ -809,13 +809,13 @@ pub fn derive_from_json_query_result(input: TokenStream) -> TokenStream { /// #[sea_orm(from_expr = "Expr::val(1).add(1)")] /// sum: i32, /// #[sea_orm(flatten)] -/// foo: Foo +/// foo: Foo, /// } /// /// #[derive(Debug, FromQueryResult, DerivePartialModel)] -/// struct Foo{ +/// struct Foo { /// #[sea_orm(from_expr = "Expr::val(12).add(2)")] -/// bar: i64 +/// bar: i64, /// } /// ``` /// Note: the `flatten` cannot use with `from_expr` or `from_col`, From 37a2103e842049a7d19b25b18bf38a96c9e91da5 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 21 Jun 2023 21:39:57 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E2=9C=85=20adding=20test=20for=20`flatte?= =?UTF-8?q?n`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/partial_model_tests.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/partial_model_tests.rs b/tests/partial_model_tests.rs index a9350045d..155987409 100644 --- a/tests/partial_model_tests.rs +++ b/tests/partial_model_tests.rs @@ -45,3 +45,21 @@ struct FieldFromExpr { #[sea_orm(from_expr = "Expr::col(Column::Id).equals(Column::Foo)")] _bar: bool, } + +#[derive(FromQueryResult, DerivePartialModel)] +struct NestWithOther { + #[sea_orm(flatten)] + _flatten1: FieldFromDiffNameColumnTest, + #[sea_orm(flatten)] + _flatten2: FieldFromExpr, +} +#[derive(FromQueryResult, DerivePartialModel)] +#[sea_orm(entity = "Entity")] +struct MixedNestTest { + #[sea_orm(flatten)] + _flatten1: FieldFromDiffNameColumnTest, + #[sea_orm(from_col = "id")] + _id: i32, + #[sea_orm(from_expr = "Column::Bar2.sum()")] + _sum: f64, +} From 1402e63f1fff828faa54d5cdb0bcc69e04452e25 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 9 Sep 2023 18:29:21 +0800 Subject: [PATCH 09/12] Update sea-orm-macros/src/derives/from_query_result.rs --- sea-orm-macros/src/derives/from_query_result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index d6aa8aad1..7585c54aa 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -49,7 +49,7 @@ pub fn expand_derive_from_query_result( let s = ident.unraw().to_string(); if *flatten{ quote! { #ident : <#ty as sea_orm::FromQueryResult>::from_query_result(#arg_row, #arg_pre)? } - }else{ + } else { quote! { #ident : #arg_row.try_get(#arg_pre, #s)?} } }) From 7a3c76419e1ba418e79547cfd4fba86a35cd43d5 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 9 Sep 2023 18:31:12 +0800 Subject: [PATCH 10/12] Update sea-orm-macros/src/derives/partial_model.rs --- sea-orm-macros/src/derives/partial_model.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-macros/src/derives/partial_model.rs b/sea-orm-macros/src/derives/partial_model.rs index 084a8852e..9950a5946 100644 --- a/sea-orm-macros/src/derives/partial_model.rs +++ b/sea-orm-macros/src/derives/partial_model.rs @@ -166,7 +166,7 @@ impl DerivePartialModel { ColumnAs::Expr { expr, field_name } => { quote!(let #select_ident = sea_orm::SelectColumns::select_column_as(#select_ident, #expr, #field_name);) }, - ColumnAs::Flatten { ty }=>{ + ColumnAs::Flatten { ty } => { quote!(let #select_ident = <#ty as sea_orm::PartialModelTrait>::select_cols(#select_ident);) } }); From f65e1516905de2a49ba083e950d86cb9dd4e9f34 Mon Sep 17 00:00:00 2001 From: Chris Tsang Date: Sat, 9 Sep 2023 18:32:45 +0800 Subject: [PATCH 11/12] Update sea-orm-macros/src/derives/from_query_result.rs --- sea-orm-macros/src/derives/from_query_result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sea-orm-macros/src/derives/from_query_result.rs b/sea-orm-macros/src/derives/from_query_result.rs index 7585c54aa..a818f8121 100644 --- a/sea-orm-macros/src/derives/from_query_result.rs +++ b/sea-orm-macros/src/derives/from_query_result.rs @@ -50,7 +50,7 @@ pub fn expand_derive_from_query_result( if *flatten{ quote! { #ident : <#ty as sea_orm::FromQueryResult>::from_query_result(#arg_row, #arg_pre)? } } else { - quote! { #ident : #arg_row.try_get(#arg_pre, #s)?} + quote! { #ident : #arg_row.try_get(#arg_pre, #s)? } } }) .collect(); From af7b422b9bc7cb3db05dbd4cc21f6801fa38b1d4 Mon Sep 17 00:00:00 2001 From: ForzenString <964413011@qq.com> Date: Wed, 20 Mar 2024 00:30:48 +0800 Subject: [PATCH 12/12] :art: cargo fmt --- .../duplicated_many_to_many_paths/bills.rs | 4 ++-- .../users_saved_bills.rs | 4 ++-- .../duplicated_many_to_many_paths/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many/bills.rs | 4 ++-- .../src/tests_cfg/many_to_many/users_votes.rs | 4 ++-- .../src/tests_cfg/many_to_many_multiple/bills.rs | 4 ++-- .../many_to_many_multiple/users_votes.rs | 12 ++++++------ .../src/tests_cfg/self_referencing/bills.rs | 8 ++------ .../src/tests_cfg/self_referencing/users.rs | 16 ++++------------ sea-orm-macros/src/derives/partial_model.rs | 1 - 10 files changed, 24 insertions(+), 37 deletions(-) diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs index a3a6911b9..baf33426e 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, #[sea_orm(has_many = "super::users_saved_bills::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs index 4ef0281cd..575bac58f 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_saved_bills.rs @@ -16,7 +16,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -24,7 +24,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs index a04ad7fa7..62f9cf7d0 100644 --- a/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/duplicated_many_to_many_paths/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs index 5a3acef9c..f2de469f0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, #[sea_orm(has_many = "super::users_votes::Entity")] diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs index a04ad7fa7..62f9cf7d0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many/users_votes.rs @@ -17,7 +17,7 @@ pub enum Relation { from = "Column::BillId", to = "super::bills::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Bills, #[sea_orm( @@ -25,7 +25,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "Cascade", - on_delete = "Cascade", + on_delete = "Cascade" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs index 5094e5885..6874aeed0 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/bills.rs @@ -5,7 +5,7 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub user_id: Option , + pub user_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -15,7 +15,7 @@ pub enum Relation { from = "Column::UserId", to = "super::users::Column::Id", on_update = "NoAction", - on_delete = "NoAction", + on_delete = "NoAction" )] Users, } diff --git a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs index 87187f4c0..29fb173cb 100644 --- a/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs +++ b/sea-orm-codegen/src/tests_cfg/many_to_many_multiple/users_votes.rs @@ -7,8 +7,8 @@ pub struct Model { pub user_id: i32, #[sea_orm(primary_key, auto_increment = false)] pub bill_id: i32, - pub user_idd: Option , - pub bill_idd: Option , + pub user_idd: Option, + pub bill_idd: Option, pub vote: bool, } @@ -17,25 +17,25 @@ pub enum Relation { #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillIdd", - to = "super::bills::Column::Id", + to = "super::bills::Column::Id" )] Bills2, #[sea_orm( belongs_to = "super::bills::Entity", from = "Column::BillId", - to = "super::bills::Column::Id", + to = "super::bills::Column::Id" )] Bills1, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserIdd", - to = "super::users::Column::Id", + to = "super::users::Column::Id" )] Users2, #[sea_orm( belongs_to = "super::users::Entity", from = "Column::UserId", - to = "super::users::Column::Id", + to = "super::users::Column::Id" )] Users1, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs index 583655f67..22cfc4690 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/bills.rs @@ -5,16 +5,12 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option , + pub self_id: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfId", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] SelfRef, } diff --git a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs index b54f3e5e2..487ba9409 100644 --- a/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs +++ b/sea-orm-codegen/src/tests_cfg/self_referencing/users.rs @@ -5,23 +5,15 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key)] pub id: i32, - pub self_id: Option , - pub self_idd: Option , + pub self_id: Option, + pub self_idd: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation { - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfId", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfId", to = "Column::Id")] SelfRef2, - #[sea_orm( - belongs_to = "Entity", - from = "Column::SelfIdd", - to = "Column::Id", - )] + #[sea_orm(belongs_to = "Entity", from = "Column::SelfIdd", to = "Column::Id")] SelfRef1, } diff --git a/sea-orm-macros/src/derives/partial_model.rs b/sea-orm-macros/src/derives/partial_model.rs index c9bc6ce80..ae743b126 100644 --- a/sea-orm-macros/src/derives/partial_model.rs +++ b/sea-orm-macros/src/derives/partial_model.rs @@ -106,7 +106,6 @@ impl DerivePartialModel { let field_name = field.ident.unwrap(); - let col_as = match (from_col, from_expr, flatten) { (None, None, false) => { if entity.is_none() {