Difference of rails between Model.count and Model.count (: all)

Is there any difference between

User.count 

and

 User.count(:all) 

I updated the rails to 4.0, then when I use ModelName.count(:all) , it works well, but if I use ModelName.count , the following error occurs. Since their bot works 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" 
+8
ruby-on-rails ruby-on-rails-4
source share
2 answers

I ran into this problem. This change has been made to this commit . Type string

 User.count 

now throws an ActiveRecord::StatementInvalid error, because it generates SELECT COUNT() FROM users in Postgres. Starting with this commit, the fix is ​​to upgrade the code to

 User.count(:all) 

This commit restores the functionality that existed before using :all as a column to pass to AREL, invoking 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 out the new commit mentioned above.

+4
source share

I think there is no difference between the two.

http://apidock.com/rails/ActiveRecord/Calculations/count http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-count

Without passing any parameters for counting, it will return the count of all rows for the model.

0
source share

All Articles