2013-08-12 3 views
0

나는 테이블, 열, 인덱스, index_column 모델이 있습니다. 관계 :이중 레벨 깊은 관계 가져 오기

표 1 .. * 열

표 1 .. * 인덱스

인덱스 1 .. * index_column 모델 테이블에 정의

관계 :

 'columns' => array(self::HAS_MANY, 'AdColumn', 'table_id'), 
     'indexes' => array(self::HAS_MANY, 'AdIndex', 'table_id'), 

관계 모델 열에 정의 됨 :

 'table' => array(self::BELONGS_TO, 'AdTable', 'table_id'), 

관계는 모델 인덱스 정의 : 모델 index_column에 정의

 'columns' => array(self:: HAS_MANY, 'AdIndexColumn', 'index_id'), 
     'table' => array(self:: BELONGS_TO, 'AdTable', 'table_id'), 

관계를 :

나는 각 행에서 테이블 컬럼의 목록이 있어야한다, (CGridView 사용) 테이블의 목록을 표시 할 필요가
 'column' => array(self::BELONGS_TO, 'AdColumn', 'column_id'), 
     'index' => array(self::BELONGS_TO, 'AdIndex', 'index_id'), 
     'table' => array(self::BELONGS_TO, 'AdTable', 'table_id'), 

및 인덱스 목록 (이름 + 열).

모델은 GII 생성, 그래서 나는 시도됩니다

$filter = new AdTable('search'); 
    $filter->unsetAttributes(); // clear any default values 
    $dataProvider = $filter->with('columns', 'indexes')->search(); 

그리고 이것은 쿼리 제작 : 위의 테이블에 대한 모든 열을 가져 오는 모든 테이블을 가져 오는에 대한

  • ,
  • 위의 테이블에 대한 모든 인덱스를 가져 오는 경우

그러나 각 인덱스에는 인덱스 열을 가져 오기위한 또 다른 쿼리가 있습니다. Yii가 한 검색어를 모두 포함하는 검색어를 좋아합니다.

답변

0

원하는 항목이 아래에 있습니까?

$filteredAdTable = AdTable::model()->with(array(
      'indexes' => array(
       'alias' => 'at', 
       //'condition' => '', 
       //'params' => array(), 
       'with' => array(
        'adIndexColumns'=>array(// 'I changed name this relation from columns to adIndexColumns not to make confusion with the relation columns of AdTable' 
         'alias' => 'aic', 
         //'condition' => '', 
         //'params' => array(), 
        ) 

       ) 
      ), 

      'columns' => array(
       'alias' => 'ac', 
       //'condition' => '', 
       //'params' => array(), 
      ) 
     ))->findAll(
      //'condition' => '', 
      //'params' => array(), 
      ); 

은 아마 당신은보고에 대한 together 옵션

http://www.yiiframework.com/wiki/527/relational-query-lazy-loading-and-eager-loading-with-and-together/

+0

유사 광산 솔루션을해야 :) – koral

관련 문제