Sha256: 2309646c98cf1f4e2ddeb506e03d3b430e12e53a9d32cdad080df6d0b92bc864

Contents?: true

Size: 1.47 KB

Versions: 37

Compression:

Stored size: 1.47 KB

Contents

# encoding: utf-8

module SportDb
  module Model

class Event < ActiveRecord::Base

  belongs_to :league
  belongs_to :season

if ActiveRecord::VERSION::MAJOR == 3
  has_many :rounds, order: 'pos'  # all (fix and flex) rounds
  has_many :groups, order: 'pos'
else
  has_many :rounds, -> { order('pos') }  # all (fix and flex) rounds
  has_many :groups, -> { order('pos') }
end

  has_many :games, :through => :rounds

  has_many :event_teams,  class_name: 'EventTeam'
  has_many :teams, :through => :event_teams

  has_many :event_grounds,  class_name: 'EventGround'
  has_many :grounds, :through => :event_grounds


  before_save :on_before_save


  def add_teams_from_ary!( team_keys )
    ## move to depreciated? used in event reader? why? why not?
    team_keys.each do |team_key|
      team = Team.find_by_key!( team_key )
      self.teams << team
    end
  end

  def on_before_save
    # event key is composite of league + season (e.g. at.2012/13) etc.
    self.key = "#{league.key}.#{season.key}"
  end
  
  def title
    "#{league.title} #{season.title}"
  end


  #####################
  ## convenience helper for text parser/reader

  ###
  ## fix: use/add  to_teams_table( rec )  for reuse
  #
  ##  @known_teams = @event.known_teams_table


  def known_teams_table
    @known_teams_table ||= TextUtils.build_title_table_for( teams )
  end # method known_teams_table

end # class Event

  end # module Model
end # module SportDb

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
sportdb-models-1.18.1 lib/sportdb/models/event.rb
sportdb-models-1.18.0 lib/sportdb/models/event.rb
sportdb-models-1.17.0 lib/sportdb/models/event.rb
sportdb-models-1.16.2 lib/sportdb/models/event.rb
sportdb-models-1.16.1 lib/sportdb/models/event.rb
sportdb-models-1.16.0 lib/sportdb/models/event.rb
sportdb-models-1.15.2 lib/sportdb/models/event.rb
sportdb-models-1.15.1 lib/sportdb/models/event.rb
sportdb-models-1.15.0 lib/sportdb/models/event.rb
sportdb-models-1.14.2 lib/sportdb/models/event.rb
sportdb-models-1.14.1 lib/sportdb/models/event.rb
sportdb-models-1.14.0 lib/sportdb/models/event.rb
sportdb-models-1.13.0 lib/sportdb/models/event.rb
sportdb-models-1.12.0 lib/sportdb/models/event.rb
sportdb-models-1.11.2 lib/sportdb/models/event.rb
sportdb-models-1.11.1 lib/sportdb/models/event.rb
sportdb-models-1.11.0 lib/sportdb/models/event.rb
sportdb-models-1.10.1 lib/sportdb/models/event.rb
sportdb-models-1.10.0 lib/sportdb/models/event.rb
sportdb-1.9.16 lib/sportdb/models/event.rb