Skip to content

Instantly share code, notes, and snippets.

@jordangraft
Created April 22, 2016 23:44
Show Gist options
  • Save jordangraft/bb90b2f084ba515159091f471af40687 to your computer and use it in GitHub Desktop.
Save jordangraft/bb90b2f084ba515159091f471af40687 to your computer and use it in GitHub Desktop.
class Order < ActiveRecord::Base
has_many :line_items
def has_many_associations
self.reflect_on_all_associations(:has_many).collect {|assoc| "#{assoc.name}_total_amount"}
end
def line_items_total_amount
line_items.sum(:amount)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment