pub fn indirect_referring_tables<'a>(&self,
                                         tables: &'a [Table])
                                         -> Vec<(&'a Table, &'a Table, &'a Column)> {
        let mut indirect_referring_tables = Vec::new();
        for (rt, column) in self.referring_tables(tables) {
            let rt_pk = rt.primary_columns();
            let rt_fk = rt.foreign_columns();
            let rt_uc = rt.uninherited_columns();
            if rt_pk.len() == 2 && rt_fk.len() == 2 && rt_uc.len() == 2 {
                // println!("{} is a candidate linker table for {}", rt.name, self.name);
                let ref_tables = rt.referred_tables(tables);
                let (_, t0) = ref_tables[0];
                let (_, t1) = ref_tables[1];
                let other_table;
                // if self.name == t0.name && self.schema == t0.schema{
                if self == t0 {
                    other_table = t1;
                } else {
                    other_table = t0;
                }
                let mut cnt = 0;
                for fk in &rt_fk {
                    if self.is_foreign_column_refer_to_primary_of_this_table(fk) {
                        cnt += 1;
                    }
                    if other_table.is_foreign_column_refer_to_primary_of_this_table(fk) {
                        cnt += 1;
                    }
                }

                if cnt == 2 {
                    indirect_referring_tables.push((other_table, rt, column))
                }
            }
        }
        indirect_referring_tables
    }
/// has many indirect
/// when there is a linker table, bypass the 1:1 relation to the linker table
/// then create a 1:M relation to the other linked table
/// Algorithmn: determine whether a table is a linker then get the other linked table
///        *get all the referring table
///        *for each table that refer to this table
///        *if there are only 2 columns and is both primary
///            and foreign key at the same time
///         and 1 of which refer to the primary column of this table
///     * then the other table that is refered is the indirect referring table
/// returns the table that is indirectly referring to this table and its linker table
has many indirect
when there is a linker table, bypass the 1:1 relation to the linker table
then create a 1:M relation to the other linked table
Algorithmn: determine whether a table is a linker then get the other linked table
get all the referring table
for each table that refer to this table
if there are only 2 columns and is both primary
and foreign key at the same time
and 1 of which refer to the primary column of this table
then the other table that is refered is the indirect referring table
returns the table that is indirectly referring to this table and its linker table
has many indirect when there is a linker table bypass the 1 : 1 relation to the linker table then create a 1 : M relation to the other linked table Algorithmn : determine whether a table is a linker then get the other linked table get all the referring table for each table that refer to this table if there are only 2 columns and is both primary and foreign key at the same time and 1 of which refer to the primary column of this table then the other table that is refered is the indirect referring table returns the table that is indirectly referring to this table and its linker table
pub fn indirect_referring_tables<'a>(&self,
                                         tables: &'a [Table])
                                         -> Vec<(&'a Table, &'a Table, &'a Column)> {
        let mut indirect_referring_tables = Vec::new();
        for (rt, column) in self.referring_tables(tables) {
            let rt_pk = rt.primary_columns();
            let rt_fk = rt.foreign_columns();
            let rt_uc = rt.uninherited_columns();
            if rt_pk.len() == 2 && rt_fk.len() == 2 && rt_uc.len() == 2 {
                // println!("{} is a candidate linker table for {}", rt.name, self.name);
                let ref_tables = rt.referred_tables(tables);
                let (_, t0) = ref_tables[0];
                let (_, t1) = ref_tables[1];
                let other_table;
                // if self.name == t0.name && self.schema == t0.schema{
                if self == t0 {
                    other_table = t1;
                } else {
                    other_table = t0;
                }
                let mut cnt = 0;
                for fk in &rt_fk {
                    if self.is_foreign_column_refer_to_primary_of_this_table(fk) {
                        cnt += 1;
                    }
                    if other_table.is_foreign_column_refer_to_primary_of_this_table(fk) {
                        cnt += 1;
                    }
                }
                if cnt == 2 {
                    indirect_referring_tables.push((other_table, rt, column))
                }
            }
        }
        indirect_referring_tables
    }
pub fn indirect_referring_tables < ' a > ( & self , tables : & ' a [ Table ] ) -> Vec < ( & ' a Table , & ' a Table , & ' a Column ) > { let mut indirect_referring_tables = Vec :: new ( ) ; for ( rt , column ) in self . referring_tables ( tables ) { let rt_pk = rt . primary_columns ( ) ; let rt_fk = rt . foreign_columns ( ) ; let rt_uc = rt . uninherited_columns ( ) ; if rt_pk . len ( ) == 2 && rt_fk . len ( ) == 2 && rt_uc . len ( ) == 2 { // println!("{} is a candidate linker table for {}", rt.name, self.name); let ref_tables = rt . referred_tables ( tables ) ; let ( _ , t0 ) = ref_tables [ 0 ] ; let ( _ , t1 ) = ref_tables [ 1 ] ; let other_table ; // if self.name == t0.name && self.schema == t0.schema{ if self == t0 { other_table = t1 ; } else { other_table = t0 ; } let mut cnt = 0 ; for fk in & rt_fk { if self . is_foreign_column_refer_to_primary_of_this_table ( fk ) { cnt += 1 ; } if other_table . is_foreign_column_refer_to_primary_of_this_table ( fk ) { cnt += 1 ; } } if cnt == 2 { indirect_referring_tables . push ( ( other_table , rt , column ) ) } } } indirect_referring_tables }
has many indirect
when there is a linker table, bypass the 1:1 relation to the linker table
then create a 1:M relation to the other linked table
Algorithmn: determine whether a table is a linker then get the other linked table
get all the referring table
for each table that refer to this table
if there are only 2 columns and is both primary
and foreign key at the same time
and 1 of which refer to the primary column of this table
 then the other table that is refered is the indirect referring table
returns the table that is indirectly referring to this table and its linker table
has many indirect when there is a linker table bypass the 1 : 1 relation to the linker table then create a 1 : M relation to the other linked table Algorithmn : determine whether a table is a linker then get the other linked table get all the referring table for each table that refer to this table if there are only 2 columns and is both primary and foreign key at the same time and 1 of which refer to the primary column of this table then the other table that is refered is the indirect referring table returns the table that is indirectly referring to this table and its linker table
&self
tables
&'a [Table]
&self
tables
&'a [Table]