I have tables 1) tours (id, title) 2) categories (id, title) 3) tours_categories (tour_id, category_id)
Model Tours:
public function relations ()
{
return array (
'Category' => array (self :: MANY_MANY,
'Categories',
'tours_categories (tour_id, category_id)'
),
);
}
Model Categories:
public function relations ()
{
return array (
'Tours' => array (self :: MANY_MANY,
'Tours',
'tours_categories (category_id, tour_id)'
),
);
}
question:
I want to search the database for the table tours_categories and select all the tours = to one category id ... how to do it correctly
In controller ToursController I want to do something like this
$tour = Tours::model()->with ('category')->findAllByAttributes (array ('category.id' => $id));
but it's not works of course. How to do it?
Btw, one minor thing, the name
category
for the relation MANY_MANY on model Tour is not congruous. It should changed tocategories
instead. Once you update it, you should also update above query of cause.