ruby - Getting wrong number when using count - Rails -
i trying total number of questions based on specific categories. used below line of code returns wrong number , cannot understand why cannot access questions directly "where" query.
def questions_total number = category.where("tag ?",'1-%').includes(:questions).count end
please guide me through mistakes thanks
use group by
sql syntax:
question.group(:category_id) .joins(:category).where('categories.tag ?', '1-%') .count
you can delete joins
line if don't want apply filter based on category attribute.
Comments
Post a Comment