2

How to create criteria->with() witout "on" or without "default relation" in query?

select *
from status kk 
inner join user tt 
left join userstatus ii on kk.status_id = ii.status_id 
    and ii.user_id = tt.user_id

I want use it for CGridView search in YII for dataProvider.

Or is there any other way that could diapakai to overcome this?

tomferon
  • 4,993
  • 1
  • 23
  • 44

2 Answers2

0

CDbCriteria::with requires you to have relations defined. If you want to manually join tables, the class also allows you to do that with the join property

http://www.yiiframework.com/doc/api/1.1/CDbCriteria#join-detail

georaldc
  • 1,880
  • 16
  • 24
0

You can define relations in your model, than use it in your search method. For example

public function relations() {
        return array(
            'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
        );
    }

and in search method:

public function search() {        
        $criteria = new CDbCriteria;
        $criteria->with = array('user');
        ......
}
Taron Saribekyan
  • 1,360
  • 7
  • 13