phpcakephpcontainscontainable

cakephp contain


I have a problem with contain :( , let me explain:

Models Relations:

Client -> hasMany -> Card -> hasAndBelongsToMany -> Partner -> hasMany -> Contact

What i need is to get all partners and contacts of Client with codigo = 24150 and Contacts with coords_lat = 38.71093.

Code:

$conditions = array('conditions' => 
   array('codigo' => '24150')
);

$contain = array(
   'contain'=> array(
    'Partner' => array(
       'Contact' => array('conditions' => array('coords_lat' => '38.71093')) 
    )
   )
);

$parceiros = $this->Client->find('all', array($conditions, $contain));

I've added

var $actsAs = array('Containable'); 

to app_model.php

To be totally honest with you, i don't really understand what is happening here... truth is that mysql does huge queries and takes tons of time but i don't see it selecting by "codigo = 24150"

I would appreciate some help.

Thanks in advance.

Rui


Solution

  • Finally fixed it, cakephp didn't like having conditions and contain in different arrays. The solution for this is:

    $conditions = array(
        'conditions' => array('codigo' => '24150'),
        'contain' => array(
            'Card'=>array(
                'Partner' => array (
                    'Contact' => array(
                        'conditions' => array('Contact.coords_lat' => '38.710930')
                     )
                 )
             )
         )
     );
    
     $parceiros = $this->Client->find('all', $conditions);