Cdbcriteria With Foreign Field

Hey Community,

got a rather tricky question but maybe the answer is simple and I am just not seeing it yet, so it would be great if someone could give me a hand here.

Scenario: I have a model EOpportunityTracker and another EOpportunity with the following relation in EOpportunity:

'opportunity'=>array(self::BELONGS_TO, 'EOpportunity', 'opportunity_id', 'with'=>array('contact')),

now I am getting what I want from the database:

$criteria = new CDbCriteria;

$criteria->with = array('opportunity');

$criteria->condition = 'creator_id=:creator_id AND t.status=:status';

$criteria->params=array(':creator_id'=>Yii::app()->user->id, ':status'=>$_POST['EOpportunityTracker']['status']);

that works perfectly fine.

Now I have another field in EOpportunity which is contact_id and I need to get only EOpportunityTracker where the contact_id is matching a $_POST parameter. Can anyone tell me how to add this to the CDbCriteria?

Thanks in advance.


Perhaps using something like this?

$criteria->compare('opportunity.contact_id', $_POST['...']);

yeah that makes totally sense! Thank you rei :)