0

I am getting empty array from CActiveDataProvider, while (property) totalItemCount returns 2.

I have 'enableParamLogging'=>true, in my config, and enabled CWebLogRoute. When I execute the generated query by CActiveDataProvider I get 2 rows, but CActiveDataProvider->data returns an empty Array.

Basically its a Employee <-> Shift Roaster editor with bootstrap and x-editable extension installed

Model

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,
    ));
}

Controller

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,
    ));
}

View

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

));

Generated Query

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 )

Results

enter image description here

print_r($roaster->getNew($model->RoasterDepId)) Gives Below Result

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] => 
)

Thanks in Advance

topher
  • 14,790
  • 7
  • 54
  • 70
Ramzy
  • 56
  • 1
  • 9
  • 1
    can you show us some code? – Developerium Oct 29 '14 at 07:10
  • @tinybyte Question Updated. – Ramzy Oct 29 '14 at 07:31
  • @Ramzy, for dataprovider you set `'dataProvider' => $roaster->getNew($model->RoasterDepId)` but this attribute `RoasterDepId` seems not set up, isn't it? – Igor Savinkin Oct 29 '14 at 07:39
  • @IgorSavinkin `RoasterDepId` attribute is set in controller where `$this->loadModel($id)` is called. Anyways value is `2`. – Ramzy Oct 29 '14 at 07:44
  • As I said, Generated Query is perfect, it shows data when i execute in Management Studio. – Ramzy Oct 29 '14 at 07:45
  • @Ramzy, in the picture i see there are still some fields not zero. How about you try `print_r($roaster->getNew($model->RoasterDepId))` to expose it. – Igor Savinkin Oct 29 '14 at 08:05
  • @Ramzy, $model is an Employee model instanse, while $roaster is an Roaster model instance, right? – Igor Savinkin Oct 29 '14 at 08:10
  • @IgorSavinkin no `$model` is `Roasters` model `Roasters` have three column `RoasterId (pk) -> Roaster.RstId (fk)`, `RoasterDepId (fk) -> Departments.DepId (pk)` and `RoasterMonth (date)` (They are two tables `Roaster` and `Roasters`) – Ramzy Oct 29 '14 at 08:14
  • @Ramzy, you try also `print_r($roaster->getNew($model->RoasterDepId)->getData())` to print out data only. – Igor Savinkin Oct 29 '14 at 08:33
  • @IgorSavinkin `print_r($roaster->getNew($model->RoasterDepId)->getData())` prints an empty array `array()` – Ramzy Oct 29 '14 at 08:34
  • @Ramzy, also it's kind of messy to have similar tables: 'Roaster` and `Roasters` – Igor Savinkin Oct 29 '14 at 08:35
  • @Ramzy, I can't help that much, since i'm not that well in the right joins. Could you transform your request to composer simpler query? – Igor Savinkin Oct 29 '14 at 08:38
  • The problem is CActiveDataProvider is returning an empty array. When I execute the generated query, it shows perfect results, I suppose this means every thing is perfect, but CActiveDataProvider is making some kind of validation and emptying the data array. – Ramzy Oct 29 '14 at 08:45

0 Answers0