Я получаю пустой массив из CActiveDataProvider, в то время как (свойство) totalItemCount возвращает 2.
У меня есть ‘enableParamLogging’ => true, в моей конфигурации, и включен CWebLogRoute. Когда я выполняю сгенерированный запрос CActiveDataProvider, я получаю 2 строки, но CActiveDataProvider-> data возвращает пустой массив.
В основном это Employee <-> Shift Roaster
редактор с bootstrap
а также 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 )
Результаты
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] =>
)
Заранее спасибо
Задача ещё не решена.
Других решений пока нет …