CakePHP supports syntax for defining your own connections. This will be done as follows:PropertiesController
$properties = $this->Property->find('all', array(
'fields' => array('Property.*'),
'joins' => array(
array(
'table' => 'locations',
'alias' => 'Location',
'type' => 'INNER',
'conditions' => array(
'Property.location_id' =>'Location.id'
)
),
),
)
);
Another way you can do it
You must create a relationship with your model and use constrained behavior, as shown below:
class Property extends AppModel {
public $actsAs = array('Containable');
public $belongsTo = array('Property');
}
class Location extends AppModel {
public $actsAs = array('Containable');
public $hasMany = array('Property');
}
Then you can do it from PropertiesController:
$properties = $this->Property->find('all', array(
'contain' => array('Location')
));
source
share