Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I count number of records in a table #2

Open
nadal opened this issue Jun 17, 2010 · 1 comment
Open

How do I count number of records in a table #2

nadal opened this issue Jun 17, 2010 · 1 comment

Comments

@nadal
Copy link

nadal commented Jun 17, 2010

Table(:users).count.to_sql is not working. What's the right way.

Looked at the test cases but could not find anything.

Thanks for all the great work.

@zacheryph
Copy link

count is attached to Arel::Expression much like sum and the other aggregate methods. to use these do something similar to this (note getting arel table from ActiveRecord:

products = Product.arel_table
products.project(Arel.sql('*').count).to_sql

and you get the following output:

=> "SELECT COUNT(*) FROM [products]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants