Class: SportDb::Model::Team

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/sportdb/models/models/team.rb,
lib/sportdb/models/models/forward.rb

Instance Method Summary collapse

Instance Method Details

#event_teamsObject

note: for now allow any key and code validates :key, format: { with: TEAM_KEY_RE, message: TEAM_KEY_MESSAGE } validates :code, format: { with: TEAM_CODE_RE, message: TEAM_CODE_MESSAGE }, allow_nil: true



23
# File 'lib/sportdb/models/models/team.rb', line 23

has_many :event_teams, class_name: 'EventTeam'

#matchesObject

fix!!! - how to do it with has_many macro? use finder_sql?

finder_sql is depreciated in Rails 4!!!
 use -> { where()  } etc.  -- try it if it works
 keep as is! best solution ??
 a discussion here -> https://github.com/rails/rails/issues/9726
 a discussion here (not really helpful) -> http://stackoverflow.com/questions/2125440/activerecord-has-many-where-two-columns-in-table-a-are-primary-keys-in-table-b


36
37
38
# File 'lib/sportdb/models/models/team.rb', line 36

def matches
  Match.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'date' )
end

#past_matchesObject



44
45
46
# File 'lib/sportdb/models/models/team.rb', line 44

def past_matches
  Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date < ?', Date.today ).order( 'date desc' )
end

#upcoming_matchesObject



40
41
42
# File 'lib/sportdb/models/models/team.rb', line 40

def upcoming_matches
  Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date > ?', Date.today ).order( 'date' )
end