Additional Criteria For Relations


I have a nested related database and I’m retrieving the data as follow:

$Criteria = new CDbCriteria();


$Criteria->with=array('employee'=>array('select'=>'name'), 'days'=>array('with'=>array('entries'=>array('with'=>array('job','overhead')))));


Above returns all matching related ‘entries’ as expected however I’m wondering how I can add another condition for ‘entries’ so it also matches the column ‘day’ of its related table with value of ‘day’ of it’s own column?

Both tables have ‘day’ column


id:1, day:mon


id:1, related_id:1, day:mon

id:2, related_id:1, day:tue

Also, the line below doesn’t seem to be working, instead of only selecting and returning ‘name’ column it returns all columns


Use relation names as table aliases in query conditions, like "".

As for the select, it seems it doesn’t work in ‘with’ param. Try setting it in the main criteria object like “t.*,”. That will select all columns from the main table.

Thank you, I think adding following line should do the trick then (haven’t tested yet)

$Criteria->condition = ‘’;

With the select I think I followed a tutorial somewhere it was an official Yii page though (might have been user submitted example no sure), will try what you have suggested