I have 2 models, weekly_report
and consult_stat
and they are organized as such:
class ConsultStat < ActiveRecord::Base
belongs_to :weekly_report
end
class WeeklyReport < ActiveRecord::Base
has_many :consult_stats
end
An attribute on my consult_stats table is :consults
and I want to retrieve the total number of consults for a given set of weekly reports.
If I'm dealing with 1 weekly_report, I can do
WeeklyReport.find(x).consult_stats.sum(:consults)
however when I try to select a group of weekly_reports:
WeeklyReport.where("start_date > ?", "2016-11-01")
and retrieve the consult sum for their consult_stats using joins
I keep getting an error.