I have a table called Landmarks and a table called Categories with a HABTM relationship to each other. I am trying to retrieve all the categories for a specific Landmark with the following code:
$this->set('selected_categories', $this->Category->find('list',
array('contain'=>array(
'Landmarks'=>array(
'conditions'=>array('Landmark.num'=>7)
)))));
I've tested the database query that results from this (as printed out in debug level 2), and it seems to get the right results, i.e. a subset of the Categories. However, when I var_dump $selected_categories in the view, I'm getting a list of ALL categories instead.
Am I missing something obvious here?
ETA: I told a lie when I said the above query was working. Something else on the page is generating the SQL query I want! Which is:
SELECT `Categories`.`num`, `CategoriesLandmark`.`category_num`,
`CategoriesLandmark`.`landmark_num`
FROM `categories` AS `Categories` JOIN `categories_landmarks`
AS `CategoriesLandmark` ON (`CategoriesLandmark`.`landmark_num` = 7
AND `CategoriesLandmark`.`category_num` = `Categories`.`num`) WHERE 1 = 1