I got this code:
$criteria=new CDbCriteria; $criteria->order = 'publishedBegin DESC, id DESC'; $criteria->join = 'LEFT JOIN project_has_product ON project_has_product.project_id=t.id'; $criteria->condition = "isPublic = 1 AND project_has_product.product_id = ".$this->_params['Project']['product_id']; #$criteria->with = array('products'=>array('condition'=>"product_id = ".$this->_params['Project']['product_id']) ); $pages=new CPagination(Project::model()->count($criteria)); $pages->pageSize=self::PAGE_SIZE; $pages->applyLimit($criteria); $sort=new CSort('Project'); $sort->applyOrder($criteria); $this->_models = Project::model()->findAll($criteria); $this->_pages = $pages;
I have two tables, project and product with a MANY_MANY relation.
What I wanted to do is selecting the records, in my case all projects which belong to a certain product, by setting the criteria with attribute.
But I could only get this working with a manual join.
Is there a way to use a CDbCriteria like described with MANY_MANY relations?