If you want to make Database Association on Selected Pages In Cakephp follow the below steps,
Below code can set association where it require and you can also reduce unnecessary queries firing to database.
- Make function in your model and set your association type, for example
class ModelName extends AppModel{
function findByXYZ($arguments){
$this->hasMany = array(
'TableNameHere' => array(
'className' => 'classnamehere',
'foreignKey' => 'foreignKeyHere',
'limit' => '1',
'dependent' => true
)
);
}
}
- Now set this function before any table data selection:
$this->ModelName->findByXYZ($params);
$this->Model->find('all');
0 Comment(s)