/**
  * Creates INNER JOIN SQL for associations.
  *
  * @param Table $from_table the table used for the FROM SQL statement
  * @return string SQL INNER JOIN fragment
  */
 public function construct_inner_join_sql(Table $from_table, $using_through = false)
 {
     if ($using_through) {
         $join_table = $from_table;
         $join_table_name = $from_table->get_fully_qualified_table_name();
         $from_table_name = Table::load($this->class_name)->get_fully_qualified_table_name();
     } else {
         $join_table = Table::load($this->class_name);
         $join_table_name = $join_table->get_fully_qualified_table_name();
         $from_table_name = $from_table->get_fully_qualified_table_name();
     }
     // need to flip the logic when the key is on the other table
     if ($this instanceof HasMany || $this instanceof HasOne) {
         $this->set_keys($from_table->class->getName());
         if ($using_through) {
             $join_primary_key = $this->keyify($this->class_name);
         } else {
             $join_primary_key = $this->foreign_key[0];
         }
         $foreign_key = $this->primary_key[0];
     } else {
         $foreign_key = $this->foreign_key[0];
         $join_primary_key = $this->primary_key[0];
     }
     return "INNER JOIN {$join_table_name} ON({$from_table_name}.{$foreign_key} = {$join_table_name}.{$join_primary_key})";
 }