STAT relation generated SQL

Not a bug actually, but a little strange feature.

Have this type of relation declared:




'commentCount'=>array(self::STAT,'Comment','postID'),



And this eager loading statement:




Post::model()->with('commentCount')->findAll($criteria)



Resulting in this SQL statement:




SELECT `postID` AS `c`, COUNT(*) AS `s` FROM `Comment` GROUP BY `postID` HAVING `Comment`.`postID` IN (1,2,3,4)



I guess HAVING is for qualifying result rows based on the value of aggregate functions, and WHERE is for qualifying result rows based on individual (column) values. So in above I expected to see something like this:




SELECT `postID` AS `c`, COUNT(*) AS `s` FROM `Comment` WHERE `Comment`.`postID` IN (1,2,3,4) GROUP BY `postID` 



The HAVING clause, potentially, doesn’t operate on the “working resultset” until it is completely built. So rows get considered for adding to the “working resultset” - based on the WHERE clause. So maybe some changes to CStatElement are necessary in this case.