Cactivedataprovider With Has_Many Relations Search Criterias. Tip Or Bug ?


I have a situation like:

class Object extends CActiveRecord {


  public function relations() {

    return array(

      'posts' => array(self::HAS_MANY, 'Post', 'id'),




Then, in some controller, I want to feed CActiveDataProvider with every Object that it’s Posts fits some criterias.

  public function actionFoo() {

    $some_criterias = 'posts.datetime = 123456789';    


    $data = new CActiveDataProvider('Object', array(

      'criteria' => array(

        'condition' => $criteria,

        'with' => array('posts'),


      'pagination' => array(

        'pageSize' => 20,




So. unless the relation is not HAS_ONE, the CDBCriteria obcject will not JOIN the Posts table to the query. It will use only the WHERE statement with posts.datetime contitions.

To achieve the expected result I had to add erase

  'with' => array('posts'),

and replace it with

  'join' => 'LEFT OUTER JOIN `incomes` `incomes` ON (`incomes`.`order_id` = `t`.`id`)',

which for me is a very bad bad solution, but works.

If anyone knows, where am I wrong, please comment. If anyone thinks that’s a bug, or maybe even a feature request, comment also.



I wonder where I’ve missed that one. Thanks!

Would be good for ‘with’ manual to be described as to use with HAS_ONE relation type.



---- added:

And i think I have to rftm again, cause it works with ‘with’ AND ‘together’ :-), anyway, thanks again!