query question

Assume that I have the following tables:

  1. book (title, year,)

  2. category (title)

  3. book_category (book_id, category_id) (M:M)

relations (Book model)


categories'=>array(self::MANY_MANY, 'Category',

' book_category (book_id, category_id)'),			

);

A book may have many categories.

$book->categories returns all categories that a certain book has.

What I want to do is to find all books with a certain category, for example, with a category with id=1.

How do I perform such a query.

try with:


$criteria= new CDbCriteria;

$criteria->condition="categories.id = 1";

$criteria->with= array('categories');


Book::model()->findAll($criteria);

Check

http://www.yiiframework.com/doc/guide/1.1/en/database.arr#performing-relational-query