@@ -72,13 +72,28 @@ def __init__(self, data: schema.Schema):
7272
7373 def _get_class (self , name : str ) -> rust .Class :
7474 cls = self ._classmap [name ]
75+ properties = [
76+ (c , p )
77+ for c , p in _get_properties (cls , self ._classmap )
78+ if "rust_skip" not in p .pragmas and not p .synth
79+ ]
80+ fields = []
81+ detached_fields = []
82+ for c , p in properties :
83+ if "rust_detach" in p .pragmas :
84+ # only generate detached fields in the actual class defining them, not the derived ones
85+ if c is cls :
86+ # TODO lift this restriction if required (requires change in dbschemegen as well)
87+ assert c .derived or not p .is_single , \
88+ f"property { p .name } in concrete class marked as detached but not optional"
89+ detached_fields .append (_get_field (c , p ))
90+ elif not cls .derived :
91+ # for non-detached ones, only generate fields in the concrete classes
92+ fields .append (_get_field (c , p ))
7593 return rust .Class (
7694 name = name ,
77- fields = [
78- _get_field (c , p )
79- for c , p in _get_properties (cls , self ._classmap )
80- if "rust_skip" not in p .pragmas and not p .synth
81- ] if not cls .derived else [],
95+ fields = fields ,
96+ detached_fields = detached_fields ,
8297 ancestors = sorted (set (a .name for a in _get_ancestors (cls , self ._classmap ))),
8398 entry_table = inflection .tableize (cls .name ) if not cls .derived else None ,
8499 )
0 commit comments