Prabha Prabha - 1 year ago 64
SQL Question

count sql query used in rails 4

How to use count query in rails 4. I try to use , but I get

undefined method `where' for 57:Fixnum

my sample code is,

@empcount = Employee.count("emp_name")
.where("org_id = ? ", current_user.org_id)

What is the error with that?

Answer Source

Employee.count("emp_name") would return the total count of the employees.emp_name. A logical re-ordering of your query should return the result you're looking for:

@empcount = Employee.where("org_id = ? ", current_user.org_id).count("emp_name")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download