<commit_before>class Team < ActiveRecord::Base

  acts_as_sluggable :title
  
  before_validation :strip_title!
  
  validates_presence_of   :title, :organisation_id
  validates_uniqueness_of :title, :scope => "organisation_id"
  validates_uniqueness_of :slug,  :scope => "organisation_id", :message => "Title is too similar to an existing one. Please change it."
  validates_format_of     :title, :with => /^[\s\.a-zA-Z0-9\-]*$/, :message => "You can only use alphanumeric characters, spaces, periods, and hyphens."
  validates_length_of     :title, :within => 4..64, :too_long => "Please use a shorter title.", :too_short => "Please use a longer title."
  
  has_many :fixture_days, 
    :class_name => 'TeamGameDay',
    :conditions => ["played = ?", false],
    :order => "date asc"
    
  has_many :result_days,
    :class_name => 'TeamGameDay',
    :conditions => ["played = ?", true],
    :order => "date desc"
  
  has_many :matches,
    :class_name => 'TeamMatch',
    :include => [:home_team, :away_team, :group],
    :order => "kickoff asc"
  
  has_many :fixtures,
    :class_name => 'TeamMatch',
    :conditions => ["played = ?", false],
    :include => [:home_team, :away_team, :group],
    :order => "kickoff asc"
  
  has_many :results,
    :class_name => 'TeamMatch',
    :conditions => ["played = ?", true],
    :include => [:home_team, :away_team, :group],
    :order => "kickoff desc"
    
  has_many :competitions,
    :finder_sql => 'SELECT c.* FROM competitions c JOIN stages s ON s.competition_id = c.id JOIN groups g ON g.stage_id = s.id JOIN groups_teams gt ON gt.group_id = g.id AND gt.team_id = #{id}'
  
  def has_fixtures?
    !self.fixtures.empty?
  end
  
  def has_results?
    !self.results.empty?
  end
  
private
 
  def strip_title!
    self.title.strip! unless self.title.nil?
  end

end<commit_msg>Fix up how teams competitions are looked up.<commit_after>class Team < ActiveRecord::Base

  acts_as_sluggable :title
  
  before_validation :strip_title!
  
  validates_presence_of   :title, :organisation_id
  validates_uniqueness_of :title, :scope => "organisation_id"
  validates_uniqueness_of :slug,  :scope => "organisation_id", :message => "Title is too similar to an existing one. Please change it."
  validates_format_of     :title, :with => /^[\s\.a-zA-Z0-9\-]*$/, :message => "You can only use alphanumeric characters, spaces, periods, and hyphens."
  validates_length_of     :title, :within => 4..64, :too_long => "Please use a shorter title.", :too_short => "Please use a longer title."
  
  has_many :fixture_days, 
    :class_name => 'TeamGameDay',
    :conditions => ["played = ?", false],
    :order => "date asc"
    
  has_many :result_days,
    :class_name => 'TeamGameDay',
    :conditions => ["played = ?", true],
    :order => "date desc"
  
  has_many :matches,
    :class_name => 'TeamMatch',
    :include => [:home_team, :away_team, :group],
    :order => "kickoff asc"
  
  has_many :fixtures,
    :class_name => 'TeamMatch',
    :conditions => ["played = ?", false],
    :include => [:home_team, :away_team, :group],
    :order => "kickoff asc"
  
  has_many :results,
    :class_name => 'TeamMatch',
    :conditions => ["played = ?", true],
    :include => [:home_team, :away_team, :group],
    :order => "kickoff desc"
    
  def competitions
    Competition.find_by_sql("SELECT c.* FROM competitions c JOIN stages s ON s.competition_id = c.id JOIN groups g ON g.stage_id = s.id JOIN groups_teams gt ON gt.group_id = g.id AND gt.team_id = #{id}")
  end
  
  def has_fixtures?
    !self.fixtures.empty?
  end
  
  def has_results?
    !self.results.empty?
  end
  
private
 
  def strip_title!
    self.title.strip! unless self.title.nil?
  end

end
{'fraction_non_alphanumeric': 0.1435110393107162, 'fraction_numerical': 0.0026925148088314485, 'mean_word_length': 3.4597839135654262, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7441979', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1292, 'n_words': 336}