I want to be able to put ‘or’ condition inside a foreach loop when defining pagination variable at the controller like below:
foreach($p as $ps){
$this->paginate = array(
'or' => array(
array('Petition.commune_id LIKE' => $commune_ids['Commune']['id'] . ","),
),Recipe
'limit' => 10
);
}
I know above is wrong but I’ve compiled the codes for demonstration purposes. Is there a way we can do this in cake?
I need to loop because I want to be able to use ids from another table (which has been fetched as an array by find method) and use this for looping in the current table which is Petitions table. $commune_ids[‘Commune’][‘id’] is what I need to loop through as or value. Alternatively the query will be like:
SELECT * FROM petitions WHERE commune_id = 971 OR commune_id = 123 OR commune_id = 321 OR commune_id = 432
but of course I can do this in find function but I would like to paginate this results…
What you want is the query:
In Cake, that’s:
So you make an array of ids which you can put into the condition. Done.