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