Files
old-roraccounting/app/models/homie.rb
2020-05-18 11:35:34 +02:00

14 lines
343 B
Ruby

class Homie < ApplicationRecord
has_many :money_moves
def self.cash(importance)
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
result = []
Homie.where(["importance > ?", importance]).map do |homie|
total = totals.fetch(homie.id, 0)
{ homie: homie, amount: total }
end
end
end