Activerecord - Where Relatedtable.column 1 = Condition

I have the following tables in my mysql database:


category (id,name, url)

recipe_categories (category_id, recipe_id)

recipes (id, name, description)

The SQL statement I want to realize looks like that:


SELECT * FROM recipes r 

INNER JOIN recipe_categories cr ON cr.recipe_id = r.id

INNER JOIN category c ON c.id = cr.category_id

WHERE c.url = "google.de"

The two models:


<?php

class RecipeCategoryModel extends CActiveRecord

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function tableName()

    {

        return 'recipe_categories';

    }




    public function relations()

    {

        return array(

            'recipes'   => array(self::MANY_MANY ,      'RecipeModel',      'recipe_has_categories(recipe_category_id,recipe_id)'),

        );

    }


    public function getActive() {

        return RecipeCategoryModel::model()->with(array(

            'recipes'=>array(

                'joinType'=>'INNER JOIN',

            ),

        ))->findAll();

    }

}


?>




<?php

class RecipeModel extends CActiveRecord

{

    public static function model($className=__CLASS__)

    {

        return parent::model($className);

    }


    public function tableName()

    {

        return 'recipes';

    }


    public function relations()

    {

        return array(

            'categories'    => array(self::MANY_MANY ,      'RecipeCategoryModel',      'recipe_has_categories(recipe_id,recipe_category_id)'),

        );

    }


    public function getMainImage() {


    }


}


?>

The problem is the WHERE-clausel. How can I realize this with ActiveRecord (with(), CDbCriteria,…)?

I fink you can just specify a condition to retrieve the specific RecipeModel objects like:





(...)


RecipeModel::model()->with(array('categories'=>array('condition'=>'categories.url=\'google.de\'')))->findAll();




Thank you!