class Player

Model for a player

Overview

Schema Information

Table name: players

id         :integer          not null, primary key
name       :string           not null
created_at :datetime         not null
updated_at :datetime         not null

Public Instance Methods

singles_team() click to toggle source

Find the singles team associated with this player

  • Returns : Team or nil

# File app/models/player.rb, line 23
def singles_team
  Team.find_by_doubles_and_first_player_id(false, self.id)
end
singles_team!() click to toggle source

Force a player to have an associated singles team. Creates a new Team if needed.

# File app/models/player.rb, line 30
def singles_team!
  team = singles_team
  unless team
    team = Team.new
    team.doubles = false
    team.first_player = self
    team.save!
  end
  team
end