I am trying to get a list of identifiers (a la find('list') ), but I cannot figure out how to do this with the appropriate model conditions.
My associations: Product hasAndBelongsToMany Category Product belongsTo Manufacturer
I want to find a list of product identifiers that are in the list of category identifiers and have a specific manufacturer seo_url. I tried tons of content with conditions, conditions that link to other models, even tried to use find ('all') to see if my conditions worked, but couldn't get anything.
I managed to get one with Product-> query (), but it is not in list format. I could iterate over the array and grab identifiers or something else, but it feels terribly non-Cakey. I want to make sure Cake still performs all the security checks of my requests and any other automatic operations. Here is the request I received:
$all_results = $return['Category']['all_results'] = $this->Product->query(' SELECT `Product`.`id` FROM `categories_products` as `CategoriesProduct` JOIN `products` as `Product` ON (`CategoriesProduct`.`product_id` = `Product`.`id`) JOIN `manufacturers` as `Manufacturer` ON (`Product`.`manufacturer_id` = `Manufacturer`.`id` AND `Manufacturer`.`seo_url` = \''.$manufacturer.'\') WHERE `CategoriesProduct`.`category_id` IN ('.implode(',', $search_categories).') ');
it returns
[all_results] => Array ( [0] => Array ( [Product] => Array ( [id] => 101787 ) ) [1] => Array ( [Product] => Array ( [id] => 100781 ) ) [2] => Array ( [Product] => Array ( [id] => 101887 ) ) [3] => Array ( [Product] => Array ( [id] => 101888 ) ) )
Note: $search_categories is a list of category identifiers (i.e.: array(12,42,24,5) )
source share