1st method
in checkout.rb:
scope :checkouts_today, -> {where(date: Date.today)}
in your view or controller:
employee.checkouts.checkouts_today.sum(:hours)
2nd method
in employee.rb
has_many :today_checkouts, class_name: "Checkout", conditions: {date: Date.today}
in your view or controller:
employee.today_checkouts.sum(:hours)
Not sure the 2nd way would work as you have a join table to get the relation between Employee
and Checkout
. As we discussed in chat, you can drop the join table, in your case I don't see where you'll need it, give your app more space.