I found a bug in CActiveRecord.
I have 2 tables in foreign key, log table BelongsTo cookie on cookie ID.
When I do like that:
$dataProvider->criteria->select='cookie_id, max(t.date) as date, count(*) as page';
The dataProvder provide the corrected data, grouped by cookie ID, but the pagination shows the number of item without groupBy.
By commenting the line
the result provided is correct.
I give a look to CActive record, and I noticed that at the line 1363
If I change in
the result is once again correct. Of corse that cannot be a solution, but maybe can be a tip.
This problem is only a consequence of this trouble FindByPk and alias
This bug don’t rise an exception, simply return the wrong result
One more bug in CActiveRecord->count();
The having condition is not taken in account while doing count().
That cannot be an expected behaviour, because
are expected to return the same result (of corse $criteria are intended without LIMIT).
I noticed that the CActiveRecord->count() create a sql query like "select count (DISTINCT tableId)", why is like that?
I guess that can be much more simple and effective to use a subquery, like
FROM ($sqlStatementWithoutLimit) as foo
That is more simple and ensure that the result of count and sizeof() will be the same.
What do you think about it?
I opened an issue for this bug, but still no answer…
I have a project completed with some mistakes because of this bug, I’d like to know at least if you will fix in the next time or if I should bypass hardcoding queries…
I bypassed this problem in my application by doing the query using CDbCriteria->join instead of CDbCriteria->with.
That not resolve the bug, but it become an "anyone problem" for me.
I opened a new topic and an issue about another problem of CActiveRecord->count().