I’m struggling to figure out how to achieve this count.
Models are User, Test, Grade
User has_many Tests, Tests has_many Grades.
each grade has a calculated score (strong_pass, pass, fail, strong_fail).
how can I get a count of each grade category?
For clarity, a User might take a Math test 4 times until they pass it. they might receive grades in the spectrum (pass, fail, etc..)
but I want to know, of all tests taken for user X, how many passes, how many fails?
user.tests.grades.passed.count is what I hoped would work. but doesn’t
(I do have named scopes for ‘passed’, ‘failed’, etc.. in Grade model)
Class Grade
def self.passed
where(:grade => "passed")
end
def self.failed
where(:grade => "failed")
end
end
You should be able to do this: