activerecordjoinyiicactivedataprovider

CdbCriteria BELONG_TO


I have a model (Inmueble) with this relation:

'direccion' => array(self::BELONGS_TO, 'Direccion', 'direccion_id_direccion'),

In this example:

$criteria=new CDbCriteria;
$criteria->addCondition('name = ' .$name,'AND');
$listInmueble=new CActiveDataProvider('Inmueble', 
                                         array('criteria' => $criteria,
                                               'pagination' => array('pageSize' => 10),
                                         ));

I accesing in the condition to the attribute name of the model Inmueble.

How can i do a CdbCriteria accesing the attributes of the relation, for example where direccion.city = 'something'?

Thanks!


Solution

  • try this

     $criteria->with = array(
        'direccion' => array(
        'condition' => 'direccion.city = :something',
        'params' => array(
         ':something' => 'someValue'
    )
        )
        );