handle add/remove homies in backend
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
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)
|
||||
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 }
|
||||
total = totals.fetch(homie.id, 0)
|
||||
{ homie: homie, amount: total }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user