Is there any difference between
User.count
and
User.count(:all)
I upgraded rails to 4.0 then when I use ModelName.count(:all)
it's working well but if I use ModelName.count
the following error occurs.By the way bot of them is working well in rails 3.2
SELECT COUNT() FROM "users"
PG::WrongObjectType: ERROR: count(*) must be used to call a parameterless aggregate function
LINE 1: SELECT COUNT() FROM "users"
I ran into this issue as well. The change was introduced in this commit. A line like
User.count
will now throw an ActiveRecord::StatementInvalid
error since it will generate SELECT COUNT() FROM users
on Postgres. As of this commit, the fix is to update your code to
User.count(:all)
This commit restores the functionality that existed previously, using :all
as the "column" to pass on to ARel, causing a valid SQL query SELECT COUNT(*) FROM users
.
My Gemfile
originally had the following (as mentioned in the comments)
gem "rails", github: "rails/rails", branch: "4-0-stable"
but I needed to run bundle update rails
to pull down the newer commit referenced above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With