Guest User

Untitled

a guest
Aug 14th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. Model Proliferation / Ability to set table name at runtime
  2. date | some_foreign_key | total
  3.  
  4. activity_by_foo
  5. activity_by_bar
  6. activity_by_baz
  7.  
  8. app/models/activity_by_foo.rb
  9. app/models/activity_by_bar.rb
  10. app/models/activity_by_baz.rb
  11.  
  12. class Activity < ActiveRecord::Base
  13. def self.totals_for_period(start_date, end_date, id)
  14. select(:total).where(:start_date => start_date, :end_date => end_date, :some_foreign_key => id).sum(:total)
  15. end
  16. end
Add Comment
Please, Sign In to add comment