Yii Framework Forum: Cactivedataprovider With Has_Many Relations Search Criterias. Tip Or Bug ? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cactivedataprovider With Has_Many Relations Search Criterias. Tip Or Bug ? Rate Topic: -----

#1 User is offline   fifik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-March 12

Posted 25 October 2012 - 10:12 AM

Hello,

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.

Regards,
Filip
0

#2 User is offline   bennouna 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,166
  • Joined: 05-January 12
  • Location:Morocco

Posted 25 October 2012 - 11:39 AM

http://www.yiiframew...together-detail
0

#3 User is offline   fifik 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 13-March 12

Posted 25 October 2012 - 02:14 PM

View Postbennouna, on 25 October 2012 - 11:39 AM, said:



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.

Cheers,
Filip

---- added:

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

This post has been edited by fifik: 25 October 2012 - 02:43 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users