I code a little project with CakePHP.
My problem is that I want to filter some data with others tables' attributes and those tables have different associations with the main table. Some have association belongsTo with it and some have hasMany.
For the belongsTo I use this syntax for filter:
if (!empty($search)) {
$words = explode(' ', $search);
foreach ($words as $word) {
$arraySearch = [];
foreach ($this->searchFields as $searchField) {
$arraySearch[$searchField . ' LIKE'] = "%$word%";
}
$query->where(['OR' => $arraySearch]);
}
}
And for hasMany I use:
$words = explode(' ', $search);
foreach ($words as $word) {
$query->matching('IssueComments', function ($q) use ($word) {
return $q->where(['IssueComments.comment LIKE' => "%$word%"]);
});
}
And I don't know how to combine those two syntaxes, because I want to merge the filters' results belongsTo and hasMany.
Is there anyone who can help me?
Thank you.