Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Issue #135: CActiveRecord::count() respects group and having #2167

Merged
merged 3 commits into from Mar 5, 2013

Conversation

Projects
None yet
5 participants
Member

klimov-paul commented Mar 4, 2013

Fixes #135
Now "CActiveRecord::count()" respects group and having.
Unit tests for "CActiveRecord" has been updated. Tests have been passed successfully.

Owner

samdark commented Mar 4, 2013

Was it tested with non-MySQL? Especially SQLite.

@ghost ghost assigned samdark Mar 4, 2013

Member

klimov-paul commented Mar 4, 2013

Test case "CActiveRecordTest" uses SQLite memory connection (line 19).

Member

klimov-paul commented Mar 4, 2013

This pull request adds logic from "CDbCommandBuilder::createCountCommand()" to "CActiveFinder::count()".

Owner

samdark commented Mar 4, 2013

Looks OK for me.

@yiisoft/core-developers any comments?

Owner

qiangxue commented Mar 4, 2013

This could potentially break BC.
Also, it is not semantically right if you do count with GROUP BY because you end up with returning the first count.

Member

klimov-paul commented Mar 4, 2013

In this fix I perform the count via sub query, which means count of the result of other query.
Group by will not affect the count result anyhow.
Also I can not see how this can break a BC, @qiangxue please provide an example of what exaclty you aware.

Actually the solution I suggest just copies the approach of "CDbCommandBuilder::createCountCommand()". Back there none has any complains.

Owner

qiangxue commented Mar 4, 2013

By BC, I mean users' existing code may rely on the fact that group-by/having is ignored in the old code.
Since you are copying the code from CDbCommandBuilder::createCountCommand(), this probably isn't a big concern then.

Member

klimov-paul commented Mar 4, 2013

As for BC: may be you should tell @zhongjq and @alexandernst the issue they request actually breaks a BC and just close the issue #135.

Owner

samdark commented Mar 4, 2013

I think we should try merging it for the next RC.

Contributor

acorncom commented Mar 5, 2013

It seems like most people who want group by/having to work with their code show up here to report bugs :-) There are regular reports of problems. Having it actually fixed and then clearly documented as one of the more major fixes would eliminate the BC concern, wouldn't it?

Owner

samdark commented Mar 5, 2013

Should be OK but we definitely need to mention it in the UPGRADE.

samdark added a commit that referenced this pull request Mar 5, 2013

Merge pull request #2167 from klimov-paul/135-ActiveRecord-count-resp…
…ect-group-and-having

Issue #135: CActiveRecord::count() respects group and having

@samdark samdark merged commit 1279019 into yiisoft:master Mar 5, 2013

Owner

samdark commented Mar 5, 2013

Owner

samdark commented Mar 5, 2013

Thanks for working on this one.

You forgot to add the params (bindParams()) to the criteria

Member

klimov-paul commented Jul 26, 2013

@simontong, it is already done by #2230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment