0

我使用联接进行此搜索。结果是正确的,但即使选择的页面大小大于结果数,yii 网格也不会显示所有结果。

这是我的代码:

        if($_GET['BaseIar']['description'] !='empty'){
            $criteria->with = array('class','classSi',);
            $this->description=$_GET['BaseIar']['description'];
            $criteria->compare('class.description', $this->description, true);
            $criteria->compare('classSi.description', $this->description, true, 'OR');
        }

以下是关系:

public function relations() {
    // NOTE: you may need to adjust the relation name and the related
    // class name for the relations automatically generated below.      
    return array( 
        'class' => array(self::HAS_ONE, 'BaseEiEquipItem', 'iar_no'),
        'classSi' => array(self::HAS_ONE, 'BaseSiReceivedItem','iar_no'),
    ); 
}

这是网格:

  $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'base-iar-grid',
    'dataProvider'=>$searchModel->search(),
    'columns'=>array(       
        array(
            'class'=>'CCheckBoxColumn',
            'id'=>'base-iar-id',        
            'selectableRows'=>2, // multiple rows can be selected       
        ),                  
        'iar_id',   
        'dateInspected',
        array( 
        'name'=>'inspectedBy', 
        'value'=>'(!empty($data->inspectedBy))?$data->inspectedBy0->person->lastName.", ".$data->inspectedBy0->person->firstName." ".$data->inspectedBy0->person->middleName:"---"',
        ),

        array(
        'name'=>'endUser',
        'value'=>'(!empty($data->endUser))?$data->endUser0->person->lastName.", ".$data->endUser0->person->firstName." ".$data->endUser0->person->middleName:"---"',
        ),
        'dateReceived',
        array(
        'name'=>'receivedBy',
        'value'=>'(!empty($data->receivedBy))?$data->receivedBy0->person->lastName.", ".$data->receivedBy0->person->firstName." ".$data->receivedBy0->person->middleName:"---"',
        ),
        array(
        'name'=>'requisitionOffice',
        'value'=>'(!empty($data->requisitionOffice))?$data->requisitionOffice0->code:"---"',
        'value'=>'$data->requisitionOffice0->code'
        ),
        'prNo',
        'poNo',

        array(
            'class'=>'InfosysButtonColumn',
            'template'=>'{view}',
            'afterDelete'=>'function(link,success,data){
                if(success){
                    jSuccess("Delete completed successfully!");                         
                }
            }',
            'buttons'=>array(
                'view' => array(
                    'label' => 'View details',
                    'url' => 'Yii::app()->createUrl("pims/IAR/BaseIar/view", array("id"=>$data["id"]))'
                        ),
            ),              
            'header'=>CHtml::activeDropDownList($model,'pageSize',array('10'=>'10','20'=>'20','30'=>'30','50'=>'50','100'=>'100','ALL'=>'All'),array('onchange'=>'$.fn.yiiGridView.update("base-iar-grid", {data:{pageSize:$(this).val()}});')),
        ),
    )
));

在 $criteria->with 中声明多个关系的正确方法可能是什么?

4

1 回答 1

0

嘿,我在with() 的文档中找到了这段示例代码,也许它会对您有所帮助:

Post::model()->with(array(
    'author'=>array('select'=>'id, name'),
    'comments'=>array('condition'=>'approved=1', 'order'=>'create_time'),
))->findAll();
于 2013-11-06T02:33:26.527 回答