Parenthesis Problem In Model Query




$model=Table1::model()->with("table2")->findAll(array("condition"=>"table2.parentid=1 and table2.isactive=1 group by t.categoryid"));




 SELECT `t`.`categoryid` AS `t0_c0`, `t`.`col2` AS

`t0_c1`, `table2`.`col3` AS `t1_c0`, `table2`.`categoryname` AS

`t1_c1`, `table2`.`parentid` AS `t1_c2` FROM `table1` `t`  LEFT OUTER JOIN `table2` `table2`

ON (`t`.`categoryid`=`table2`.`categoryid`)  WHERE (table2.parentid=1

and table2.isactive=1 group by t.categoryid)

parenthesis create problem when i execute this query in my query browser. How to remove this parenthesis?

you can’t use group by this way if you want your query to work well, it’s better to use CDbCriteria




$criteria=new CDbCriteria;

$criteria->condition='table2.parentid=1 and table2.isactive=1';

$criteria->group='t.categoryid';

$model=Table1::model()->with("table2")->findAll($criteria);