문제

I want to have cakephp paginate data and still use containable, but for some reason it seems to ignore my pleas to contain anything and just gives me back the entire Tenant row. In my TenantsController I have the following code:

$conditions = array('ManagersTenant.manager_id'=>$this->Auth->User('id'));
$this->Tenant->ManagersTenant->recursive = 1;
$this->set('tenants',$this->paginate($this->Tenant->ManagersTenant, $conditions, array(
        'recursive'=>1,
        'contain'=>array(
            'username'
            )
        )
    ));

I'm simply trying to retrieve a Tenant but display only the username (Tenant is just an alias for my User model).

What am I doing wrong here? If it helps, cakephp is throwing an Undefined Index: Group notice at me under the Group column. I believe my model relationships are find because I can make cake retrieve the right data using find(), it's just when I try to use pagination that it breaks.

도움이 되었습니까?

해결책

Firstly, you need to use the model name as the key:

...'contain' => array('Tenant' => array('username'))

Secondly, using the Containable behaviour trumps recursive, so don't bother setting it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top