Sha256: 23371c35a588f6ba3dfc44152b7a41a12edb80b16a541d12e0512823d9889fbd

Contents?: true

Size: 1.26 KB

Versions: 45

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8

module SportDb
  module Model


class AlltimeStanding < ActiveRecord::Base

  self.table_name = 'alltime_standings'

  has_many :entries,  class_name: 'SportDb::Model::AlltimeStandingEntry', foreign_key: 'alltime_standing_id', :dependent => :delete_all


  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  # method recalc_for_league!


end # class AlltimeStanding


  end # module Model
end # module SportDb

Version data entries

45 entries across 45 versions & 2 rubygems

Version Path
sportdb-models-1.19.1 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.19.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.6 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.5 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.4 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.3 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.2 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.1 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.18.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.17.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.16.2 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.16.1 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.16.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.15.2 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.15.1 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.15.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.14.2 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.14.1 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.14.0 lib/sportdb/models/stats/alltime_standing.rb
sportdb-models-1.13.0 lib/sportdb/models/stats/alltime_standing.rb