1313
1414
1515try :
16-     from  sqlalchemy  import  CheckConstraint , UniqueConstraint 
16+     from  sqlalchemy  import  JSON ,  CheckConstraint ,  Column , UniqueConstraint 
1717    from  sqlmodel  import  Field , Relationship , SQLModel 
1818except  ImportError  as  import_error :
1919    import_error .msg  +=  "; Did you install fundamend[sqlmodels] or did you try to import from fundamend.models instead?" 
@@ -341,6 +341,15 @@ class Anwendungsfall(SQLModel, table=True):
341341    pruefidentifikator : str  =  Field (index = True )  #: e.g. '25001' 
342342    beschreibung : str  =  Field (index = True )  #: e.g. 'Berechnungsformel' 
343343    kommunikation_von : str   #: e.g. 'NB an MSB / LF' 
344+     kommunikationsrichtungen : list [dict [str , str ]] |  None  =  Field (default = None , sa_column = Column (JSON ))
345+     """ 
346+     JSON column containing a list of dicts with keys 'sender' and 'empfaenger'. 
347+     The columns value can be deserialized as list[Kommunikationsrichtung]. 
348+     The column contains no more information than the stringly typed 'kommunikation_von' column alone, 
349+     but it's parsed already and hence easier to use and query. 
350+     """ 
351+     # we use a json column because setting up a separate table and FK relationships for this seems overkill 
352+     # https://stackoverflow.com/a/70659555/10009545 
344353    format : EdifactFormat  =  Field (index = True )  #: e.g. 'UTILTS' 
345354    segments : list [Segment ] =  Relationship (back_populates = "anwendungsfall" )
346355    segment_groups : list [SegmentGroup ] =  Relationship (back_populates = "anwendungsfall" )
@@ -356,6 +365,11 @@ def from_model(cls, model: PydanticAnwendungsfall, position: Optional[int] = Non
356365            pruefidentifikator = model .pruefidentifikator ,
357366            beschreibung = model .beschreibung ,
358367            kommunikation_von = model .kommunikation_von ,
368+             kommunikationsrichtungen = (
369+                 [kr .model_dump (mode = "json" ) for  kr  in  model .kommunikationsrichtungen ]
370+                 if  model .kommunikationsrichtungen  is  not None 
371+                 else  None 
372+             ),
359373            format = model .format ,
360374            position = position ,
361375        )
@@ -373,6 +387,7 @@ def to_model(self) -> PydanticAnwendungsfall:
373387            pruefidentifikator = self .pruefidentifikator ,
374388            beschreibung = self .beschreibung ,
375389            kommunikation_von = self .kommunikation_von ,
390+             # the kommunikationsrichtungen are a computed property, so we reconstruct it from the kommunikation_von str 
376391            format = self .format ,
377392            elements = tuple (
378393                x .to_model ()
0 commit comments