Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top