yii combining addColumnCondition in CDbCriteria
Posted
by
keeg
on Stack Overflow
See other posts from Stack Overflow
or by keeg
Published on 2012-12-17T04:55:32Z
Indexed on
2012/12/17
5:03 UTC
Read the original article
Hit count: 545
yii
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)
© Stack Overflow or respective owner