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

14 lines
342 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
2020-09-12 01:26:56 +03:00
belongs_to :chip
2019-06-22 06:17:48 +02:00
def self.cash(importance)
2020-09-12 01:26:56 +03:00
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
2019-06-22 06:17:48 +02:00
Homie.where(["importance > ?", importance]).map do |homie|
2020-09-12 01:26:56 +03:00
total = totals.fetch(homie.id, 0)
{ homie: homie, amount: total }
2019-06-22 06:17:48 +02:00
end
end
2019-06-20 22:47:39 +02:00
end