@@ -689,6 +689,7 @@ fn process_event(event: &Event, mut state: &mut State) -> Step {
689
689
if state. path == table. columns [ i] . path { // This start tag matches one of the defined columns
690
690
// Handle the 'seri' case where this column is a virtual auto-incrementing serial
691
691
if let Some ( ref serial) = table. columns [ i] . serial {
692
+ // if table.cardinality == Cardinality::ManyToOne { continue; }
692
693
if table. columns [ i] . value . borrow ( ) . is_empty ( ) {
693
694
let id = serial. get ( ) +1 ;
694
695
let idstr = id. to_string ( ) ;
@@ -837,10 +838,14 @@ fn process_event(event: &Event, mut state: &mut State) -> Step {
837
838
let rowid;
838
839
if let Some ( domain) = table. domain . as_ref ( ) {
839
840
let mut domain = domain. borrow_mut ( ) ;
840
- if !domain. map . contains_key ( & table. lastid . borrow ( ) . to_string ( ) ) {
841
+ let key = match table. columns [ 0 ] . serial {
842
+ Some ( _) => table. columns [ 1 ..] . iter ( ) . map ( |c| c. value . borrow ( ) . to_string ( ) ) . collect :: < String > ( ) ,
843
+ None => table. lastid . borrow ( ) . to_string ( )
844
+ } ;
845
+ if !domain. map . contains_key ( & key) {
841
846
domain. lastid += 1 ;
842
847
rowid = domain. lastid ;
843
- domain. map . insert ( table . lastid . borrow ( ) . to_string ( ) , rowid) ;
848
+ domain. map . insert ( key , rowid) ;
844
849
if table. columns . len ( ) == 1 {
845
850
domain. table . write ( & format ! ( "{}\t " , rowid) ) ;
846
851
}
@@ -869,7 +874,7 @@ fn process_event(event: &Event, mut state: &mut State) -> Step {
869
874
}
870
875
domain. table . write ( "\n " ) ;
871
876
}
872
- else { rowid = * domain. map . get ( & table . lastid . borrow ( ) . to_string ( ) ) . unwrap ( ) ; }
877
+ else { rowid = * domain. map . get ( & key ) . unwrap ( ) ; }
873
878
if table. columns . len ( ) == 1 { // Single column many-to-many subtable; needs the id from the domain map
874
879
table. write ( & format ! ( "{}" , rowid) ) ;
875
880
}
@@ -884,17 +889,32 @@ fn process_event(event: &Event, mut state: &mut State) -> Step {
884
889
}
885
890
}
886
891
else { // Many-to-one relation; write the id of this subtable into the parent table
887
- state. parentcol . unwrap ( ) . value . borrow_mut ( ) . push_str ( & table. lastid . borrow ( ) ) ;
888
892
if let Some ( domain) = table. domain . as_ref ( ) {
889
893
let mut domain = domain. borrow_mut ( ) ;
890
- if domain. map . contains_key ( & table. lastid . borrow ( ) . to_string ( ) ) {
894
+ let key = match table. columns [ 0 ] . serial {
895
+ Some ( _) => table. columns [ 1 ..] . iter ( ) . map ( |c| c. value . borrow ( ) . to_string ( ) ) . collect :: < String > ( ) ,
896
+ None => table. lastid . borrow ( ) . to_string ( )
897
+ } ;
898
+ if domain. map . contains_key ( & key) {
899
+ if table. columns [ 0 ] . serial . is_some ( ) {
900
+ state. parentcol . unwrap ( ) . value . borrow_mut ( ) . push_str ( & format ! ( "{}" , * domain. map. get( & key) . unwrap( ) ) ) ;
901
+ }
902
+ else { state. parentcol . unwrap ( ) . value . borrow_mut ( ) . push_str ( & table. lastid . borrow ( ) ) ; }
891
903
table. clear_columns ( ) ;
892
904
state. table = state. tables . pop ( ) . unwrap ( ) ;
893
905
return Step :: Repeat ;
894
906
}
895
- domain. map . insert ( table. lastid . borrow ( ) . to_string ( ) , 0 ) ;
907
+ domain. lastid += 1 ;
908
+ let id = domain. lastid ;
909
+ domain. map . insert ( key, id) ;
896
910
// The for loop below will now write out the new row
897
911
}
912
+ if state. parentcol . unwrap ( ) . value . borrow ( ) . is_empty ( ) {
913
+ state. parentcol . unwrap ( ) . value . borrow_mut ( ) . push_str ( & table. lastid . borrow ( ) ) ;
914
+ }
915
+ else if allow_iteration ( state. parentcol . unwrap ( ) , & state. settings ) {
916
+ // TODO: make it do something...
917
+ }
898
918
}
899
919
}
900
920
// Now write out the other column values
0 commit comments