Files
old-roraccounting/app/models/homie.rb

14 lines
343 B
Ruby
Raw Normal View History

2019-06-20 22:47:39 +02:00
class Homie < ApplicationRecord
2020-05-18 11:35:34 +02:00
has_many :money_moves
2019-06-22 06:17:48 +02:00
def self.cash(importance)
2020-05-18 11:35:34 +02:00
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
2019-06-22 06:17:48 +02:00
result = []
Homie.where(["importance > ?", importance]).map do |homie|
2020-05-18 11:35:34 +02:00
total = totals.fetch(homie.id, 0)
2019-06-22 06:17:48 +02:00
{ homie: homie, amount: total }
end
end
2019-06-20 22:47:39 +02:00
end