Files
old-roraccounting/app/models/homie.rb
2020-09-12 01:26:56 +03:00

14 lines
342 B
Ruby

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