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'),

モデル インデックスで定義された関係:

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

モデル index_column で定義された関係:

        'column' => array(self::BELONGS_TO, 'AdColumn', 'column_id'),
        'index' => array(self::BELONGS_TO, 'AdIndex', 'index_id'),
        'table' => array(self::BELONGS_TO, 'AdTable', 'table_id'),

テーブルのリストを(CGridViewを使用して)表示する必要があります。各行には、テーブルの列のリストとインデックスのリスト(名前+列)が必要です。

モデルはGiiで生成されるので、試しました:

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

そして、これによりクエリが生成されました:

  • すべてのテーブルをフェッチするために、
  • 上記のテーブルのすべての列を取得するため
  • 上記のテーブルのすべてのインデックスを取得するため

ただし、インデックスごとに、インデックス列を取得するための別のクエリがあります。Yii によってすべてが 1 つのクエリにまとめられたクエリが好きです。

4

1 に答える 1

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/

于 2013-08-13T05:00:01.557 に答える