Prabha Prabha - 4 months ago 11
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

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")