I have a nested related database and I’m retrieving the data as follow:
$Criteria = new CDbCriteria();
$Criteria->compare('company_id',$userObject->profile->company_id);
$Criteria->with=array('employee'=>array('select'=>'name'), 'days'=>array('with'=>array('entries'=>array('with'=>array('job','overhead')))));
$this->_model=TimesheetEmployee::model()->findAll($Criteria);
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?
Use relation names as table aliases in query conditions, like "entries.day".
As for the select, it seems it doesn’t work in ‘with’ param. Try setting it in the main criteria object like “t.*, employee.name”. 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 = ‘entries.day=days.day’;
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