Sha256: 204529513f9de8e5cdb900491f52ecc61f1401a95e54c5562e9d8c65d22adc63

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 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 )

    recs = StandingsHelper.calc_for_events( league.events )

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


end # class AlltimeStanding


  end # module Model
end # module SportDb

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sportdb-1.8.27 lib/sportdb/models/stats/alltime_standing.rb