yii combining addColumnCondition in CDbCriteria
- by keeg
I have a couple of dropdown filters in my GridView, in the search part of my model I have:
if ($this->agent_primary != "") {
$criteria->addColumnCondition(array('agent_type_id'=>1, 'agent.agent_id'=>$this->agent_primary));
}
if ($this->agent_voice != "") {
$criteria->addColumnCondition(array('agent_type_id'=>2, 'agent.agent_id'=>$this->agent_voice));
}
if ($this->agent_commercial != "") {
$criteria->addColumnCondition(array('agent_type_id'=>3, 'agent.agent_id'=>$this->agent_commercial));
}
I need to somehow combine this so if someone selects two of the three dropdowns (or all three) they get the correct results, currently the sql has there WHERE in separate brackets for each addColumnCondition:
WHERE (condition1a = a AND condition1b = b) AND (condition2a = a AND condition2b = b)
instead of
WHERE (condition1a = a AND condition1b = b) OR (condition2a = a AND condition2b = b)