CActiveDataProvider返回Empty Array

时间:2014-10-29 06:59:35

标签: php sql-server yii right-join

我从CActiveDataProvider获取空数组,而(property)totalItemCount返回2.

我的配置中有'enableParamLogging'=> true,并启用了CWebLogRoute。当我通过CActiveDataProvider执行生成的查询时,我得到2行,但CActiveDataProvider->数据返回一个空数组。

基本上是安装了Employee <-> Shift Roasterbootstrap扩展程序的x-editable编辑器

模型

public function relations()
{
    return array(
        'rstEmp' => array(self::BELONGS_TO, 'Employee', 'RstEmpId'),
    );
}
public function getNew($depId){
    $criteria=new CDbCriteria;
    $criteria->with = array(
        'rstEmp' => array(
            'select'    =>  'EmpId, EmpFirstName, EmpLastName',
            'condition' =>  'EmpDepId='.$depId.' AND EmpRoaster=1 ',
            'joinType'  =>  'RIGHT JOIN',
            'on'        =>  'RstId='.$this->RstId,
        )
    );
    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
    ));
}

控制器

public function actionUpdate($id)
{
    $this->layout='//layouts/column1';
    $model=$this->loadModel($id);
    $roaster=new Roaster;
    $roaster->RstId=$id;
    $this->render('update',array(
        'model'=>$model,
        'roaster'=>$roaster,
    ));
}

查看

$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'usergrid',
'itemsCssClass' => 'table-bordered items',
'dataProvider' => $roaster->getNew($model->RoasterDepId),
'columns'=>array(
    'RstEmpId',
    array(
       'name' => 'RstEmpId',
       'value'=>'$data->rstEmp->EmpFirstName." ".$data->rstEmp->EmpLastName ',
    ),
    array( 
          'class' => 'editable.EditableColumn',
          'name' => 'd01',
          'editable' => array(
              'type'     => 'select',
              'url'      => $this->createUrl('Roasters/addRoasterEmployee'),
              'source'   => $this->createUrl('getShifts', array('id'=>$roaster->RstId)),
          )
    ),
),

));

生成查询

SELECT TOP 10 
[t].[RstId] AS [t0_c0], 
[t].[RstEmpId] AS [t0_c1], 
[t].[d01] AS [t0_c2], 
[rstEmp].[EmpId] AS [t1_c0], 
[rstEmp].[EmpFirstName] AS [t1_c1], 
[rstEmp].[EmpLastName] AS [t1_c2] 
FROM [rehman].[Roaster] [t]  RIGHT JOIN [rehman].[Employee] [rstEmp] 
ON ([t].[RstEmpId]=[rstEmp].[EmpId]) AND (RstId=2)  
WHERE (EmpDepId=2 AND EmpRoaster=1 )

结果

enter image description here

print_r($roaster->getNew($model->RoasterDepId))给出以下结果

CActiveDataProvider Object
(
[modelClass] => Roaster
[model] => Roaster Object
    (
        [shifts] => Array
            (
            )

        [_new:CActiveRecord:private] => 1
        [_attributes:CActiveRecord:private] => Array
            (
                [RstId] => 2
            )

        [_related:CActiveRecord:private] => Array
            (
            )

        [_c:CActiveRecord:private] => 
        [_pk:CActiveRecord:private] => 
        [_alias:CActiveRecord:private] => t
        [_errors:CModel:private] => Array
            (
            )

        [_validators:CModel:private] => 
        [_scenario:CModel:private] => insert
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )

[keyAttribute] => 
[_criteria:CActiveDataProvider:private] => CDbCriteria Object
    (
        [select] => *
        [distinct] => 
        [condition] => 
        [params] => Array
            (
            )

        [limit] => -1
        [offset] => -1
        [order] => 
        [group] => 
        [join] => 
        [having] => 
        [with] => Array
            (
                [rstEmp] => Array
                    (
                        [select] => EmpId, EmpFirstName, EmpLastName
                        [condition] => EmpDepId=2 AND EmpRoaster=1 
                        [joinType] => RIGHT JOIN
                        [on] => RstId=2
                    )

            )

        [alias] => 
        [together] => 
        [index] => 
        [scopes] => 
        [_e:CComponent:private] => 
        [_m:CComponent:private] => 
    )

[_countCriteria:CActiveDataProvider:private] => 
[_id:CDataProvider:private] => Roaster
[_data:CDataProvider:private] => 
[_keys:CDataProvider:private] => 
[_totalItemCount:CDataProvider:private] => 
[_sort:CDataProvider:private] => 
[_pagination:CDataProvider:private] => 
[_e:CComponent:private] => 
[_m:CComponent:private] => 
)

先谢谢

0 个答案:

没有答案