Or Conditions In Cdbcriteria With Multiple Tables


I’ve been working with Yii for two months now and since this is my first forum post I did not have that much troubles to get along with it. Currently I am stuck with the translation of a rather simple MySql query to Yii:

select * from projects p, projectparticipants pp


p.projectleader_id = 100 or

(pp.project_id = p.id and pp.participant_id = 100)

I need this query as CDbCriteria which is used in a CActiveDataProvider object for a GridView (zii.widgets.grid.CGridView).

This GridView is supposed to show all projects which have something to do with a certain user (either being a project’s leader or being participant in another leader’s project).

There might be the possiblitiy to use Yii::app()->db->createCommand() and not using a CActiveDataProvider but a different one (like CArrayDataProvider), but in my code there are several configurations for the dataprovider and all of them work together with CActiveDataProvider and CDbCriteria …

Does anyboy have got a clue how to handle this problem?

Thank you!

Okay, writing the post gave me the chance to formulate and think about the problem properly.

It works with:

$criteria = new CDbCriteria();

$criteria->compare('projectleader_id', Yii::app()->user->id, false, 'OR');


	'join' => 'LEFT JOIN projectparticipants pp ON pp.project_id = t.id',

	'condition' => 'pp.participant_id = "'.Yii::app()->user->id.'"'


How about:

$criteria = new CDbCriteria;

$criteria->with = 'participants';

$criteria->condition = 't.projectleader_id = :id OR participants.participant_id = :id';

$criteria->params = array('id'=>100);

That’s assuming that the relation has already been correctly configured.

I have a table "cartoon" with relation "userCartoons" and usercartoon table has a column with c_status

but i have the problem using

$dataProvider=new CActiveDataProvider(‘Cartoon’, array(

'criteria' => array(

    'with' =>array('userCartoons'=>array('alias'=>'user')),

    'condition' =>'t.archive_status=0 AND t.date_status=0 AND user.c_status = 0' 


Unknown column ‘user.c_status’ in ‘where clause’.

Any on ecan tell me about the solution