@@ -10,7 +10,9 @@ use super::{
1010 circular:: detect_circular_fields,
1111 file_lookup:: find_model_from_schema_path,
1212 seaorm:: { RelationFieldInfo , convert_type_with_chrono} ,
13- type_utils:: { is_seaorm_relation_type, snake_to_pascal_case} ,
13+ type_utils:: {
14+ extract_module_path_from_schema_path, is_seaorm_relation_type, snake_to_pascal_case,
15+ } ,
1416} ;
1517use crate :: parser:: { extract_rename_all, extract_skip} ;
1618
@@ -69,6 +71,16 @@ pub fn generate_inline_relation_type_from_def(
6971 // Parse the model struct
7072 let parsed_model: syn:: ItemStruct = syn:: parse_str ( model_def) . ok ( ) ?;
7173
74+ // IMPORTANT: Use the TARGET model's module path for type resolution, not the parent's.
75+ // This ensures enum types like `AuthProvider` are resolved to `crate::models::user::AuthProvider`
76+ // instead of incorrectly using the parent module path.
77+ let target_module_path = extract_module_path_from_schema_path ( & rel_info. schema_path ) ;
78+ let effective_module_path = if target_module_path. is_empty ( ) {
79+ source_module_path
80+ } else {
81+ & target_module_path
82+ } ;
83+
7284 // Detect circular fields
7385 let circular_fields = detect_circular_fields ( "" , source_module_path, model_def) ;
7486
@@ -125,7 +137,8 @@ pub fn generate_inline_relation_type_from_def(
125137
126138 // Convert SeaORM datetime types to chrono equivalents
127139 // This prevents users from needing to import sea_orm::prelude::DateTimeWithTimeZone
128- let converted_ty = convert_type_with_chrono ( & field. ty , source_module_path) ;
140+ // Use the target model's module path to correctly resolve enum types
141+ let converted_ty = convert_type_with_chrono ( & field. ty , effective_module_path) ;
129142 fields. push ( InlineField {
130143 name : field_ident. clone ( ) ,
131144 ty : converted_ty,
@@ -180,6 +193,16 @@ pub fn generate_inline_relation_type_no_relations_from_def(
180193 // Parse the model struct
181194 let parsed_model: syn:: ItemStruct = syn:: parse_str ( model_def) . ok ( ) ?;
182195
196+ // IMPORTANT: Use the TARGET model's module path for type resolution, not the parent's.
197+ // This ensures enum types like `StoryStatus` are resolved to `crate::models::story::StoryStatus`
198+ // instead of incorrectly using the parent module path.
199+ let target_module_path = extract_module_path_from_schema_path ( & rel_info. schema_path ) ;
200+ let effective_module_path = if target_module_path. is_empty ( ) {
201+ source_module_path
202+ } else {
203+ & target_module_path
204+ } ;
205+
183206 // Get rename_all from model (or default to camelCase)
184207 let rename_all =
185208 extract_rename_all ( & parsed_model. attrs ) . unwrap_or_else ( || "camelCase" . to_string ( ) ) ;
@@ -221,7 +244,8 @@ pub fn generate_inline_relation_type_no_relations_from_def(
221244
222245 // Convert SeaORM datetime types to chrono equivalents
223246 // This prevents users from needing to import sea_orm::prelude::DateTimeWithTimeZone
224- let converted_ty = convert_type_with_chrono ( & field. ty , source_module_path) ;
247+ // Use the target model's module path to correctly resolve enum types
248+ let converted_ty = convert_type_with_chrono ( & field. ty , effective_module_path) ;
225249 fields. push ( InlineField {
226250 name : field_ident. clone ( ) ,
227251 ty : converted_ty,
0 commit comments