Sha256: c94563d0d2a109546c798f87c01f4f42310bef8367010881ed5086c6f421d45d

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8

module SportDb
  module Model

class Event < ActiveRecord::Base

  belongs_to :league
  belongs_to :season

  has_many :matches, -> { order('pos') }, class_name: 'Match'

  has_many :rounds,  -> { order('pos') }
  has_many :groups,  -> { order('pos') }
  has_many :stages

  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 on_before_save
    # event key is composite of league + season (e.g. at.2012/13) etc.
    self.key = "#{league.key}.#{season.key}"
  end

  def name
    ## todo/fix: check attr_reader(:name) or such first if NOT nil !!
    "#{league.name} #{season.name}"
  end

end # class Event


class EventTeam < ActiveRecord::Base
  self.table_name = 'events_teams'

  belongs_to :event
  belongs_to :team
end # class EventTeam


class EventGround < ActiveRecord::Base
  self.table_name = 'events_grounds'

  belongs_to :event
  belongs_to :ground
end # class EventGround

  end # module Model
end # module SportDb

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sportdb-models-2.1.0 lib/sportdb/models/models/event.rb
sportdb-models-2.0.3 lib/sportdb/models/models/event.rb
sportdb-models-2.0.2 lib/sportdb/models/models/event.rb
sportdb-models-2.0.1 lib/sportdb/models/models/event.rb
sportdb-models-2.0.0 lib/sportdb/models/models/event.rb