/** * Produces join SQL like get_join_sql, except instead of joining the primary table to the * secondary table, does the inverse: joins the secondary table to the primary one. (Eg, isntead of * " LEFT JOIN secondary_table_table AS Secondary ON ..." like get_join_sql, this function returns * " LEFT JOIN primary_table AS Primary ON ...". * This is useful if the secondary table is already included in the SQL, but the primary table is not yet. * @return string */ function get_inverse_join_sql($secondary_table_alias_with_model_chain_prefix) { $primary_table_name = $this->get_table_to_join_with()->get_table_name(); $primary_table_alias = EE_Model_Parser::get_prefix_from_table_alias_with_model_relation_chain_prefix($secondary_table_alias_with_model_chain_prefix) . $this->get_table_to_join_with()->get_table_alias(); $primary_table_pk = $this->get_table_to_join_with()->get_pk_column(); //$this->get_pk_column(); $fk = $this->get_fk_on_table(); $join_sql = " LEFT JOIN {$primary_table_name} AS {$primary_table_alias} ON {$primary_table_alias}.{$primary_table_pk} = {$secondary_table_alias_with_model_chain_prefix}.{$fk} "; if ($this->get_extra_join_conditions()) { $join_sql .= "AND " . $this->get_extra_join_conditions(); } return $join_sql; }