Class: SportDb::Model::AlltimeStanding

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/sportdb/models/stats/alltime_standing.rb

Instance Method Summary collapse

Instance Method Details

#recalc_for_league!(league, opts = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sportdb/models/stats/alltime_standing.rb', line 14

def recalc_for_league!( league, opts={} )

  recs = StandingsHelper.calc_for_events( league.events, opts )

  ## - remove (if exit) old entries and add new entries
  entries.delete_all    # note: assoc dependent set to :delete_all (defaults to :nullify)

  recs.each do |team_key,rec|
   
    team = Team.find_by_key!( team_key )
    ### note: we also add rec.recs (appearance counter) - not included w/ group or event standings, for example
    entries.create!(
              team_id: team.id,
              pos:     rec.pos,
              played:  rec.played,
              won:     rec.won,
              drawn:   rec.drawn,
              lost:    rec.lost,
              goals_for: rec.goals_for,
              goals_against: rec.goals_against,
              pts:     rec.pts,
              recs:    rec.recs )
  end
end