Пример #1
0
 /**
  * 
  * Returns an INNER JOIN specification for joining to the native table as
  * as sub-SELECT.
  * 
  * @param Solar_Sql_Model_Params_Eager $eager The eager params.
  * 
  * @param Solar_Sql_Model_Params_Fetch $fetch The native fetch settings.
  * 
  * @param string $col The foreign column to join against.
  * 
  * @return array A join specification array.
  * 
  */
 protected function _getNativeBySelect($eager, $fetch, $col)
 {
     // get a *copy* of the fetch params; don't want to mess them up
     // for other eagers. only use the joins marked "keep".
     $clone = $fetch->cloneForKeeps();
     // reset the column list and get only the native column
     $clone['cols'] = array();
     $clone->cols($this->native_col);
     // for all sub-eagers, if they are joining to the top-level fetch,
     // make sure they are join_only ... otherwise, they'll add columns,
     // which will mess up our cols() from earlier.
     foreach ($clone['eager'] as $sub_eager) {
         if ($sub_eager['join_flag']) {
             $sub_eager['join_only'] = true;
         }
     }
     // don't waste time ordering the results
     $clone['order'] = false;
     // build a select and get it as a string
     $select = $this->_native_model->newSelect($clone);
     $string = $select->__toString();
     $join = array('type' => "inner", 'name' => "({$string}) AS {$fetch['alias']}", 'cond' => "{$fetch['alias']}.{$this->native_col} = {$col}", 'cols' => null);
     // done!
     return $join;
 }