class SportDb::Model::Team
FIX: add ?
use single table inheritance STI ???? - to mark two dervided classes e.g. - Club ??? - why? why not? - NationalTeam ??? - why? why not?
Private Instance Methods
matches()
click to toggle source
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
# File lib/sportdb/models/models/team.rb, line 35 def matches Match.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'date' ) end
past_matches()
click to toggle source
# File lib/sportdb/models/models/team.rb, line 43 def past_matches Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date < ?', Date.today ).order( 'date desc' ) end
upcoming_matches()
click to toggle source
# File lib/sportdb/models/models/team.rb, line 39 def upcoming_matches Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date > ?', Date.today ).order( 'date' ) end