2014-02-22 6 views
0

팀에 속한 선수에게 투표 할 수있는 시스템이 있습니다. 또한 특정 월의 팀에서 투표 및 각 플레이어의 지위를 추적하는 게재 위치 모델을 보유하고 있습니다. 많은 사람들과 일하는 방법 많은 관계를 통해

class Team < ActiveRecord::Base 
    has_many :players, dependent: :destroy 
    has_many :placements, through: :players 

class Player < ActiveRecord::Base 
    belongs_to :team 
    has_many :votes, dependent: :destroy 
    has_many :placements 

class Placement < ActiveRecord::Base 
    belongs_to :player 
    attr_accessible :month, :player_id, :points, :position 

class Vote < ActiveRecord::Base 
    belongs_to :player 
    attr_accessible :phone_id, :player_id 

그리고

는 '리더 보드'를 검색하기 위해 내가 할 :

@leaderboard = @team.placements.includes(:player).where(month: Date.today.beginning_of_month).order('points desc') 

내가 다른 팀이 (환상 리그 유사) 풀에 가입 할 수있는 풀의 아이디어를 소개합니다. 이렇게하면 팀원뿐만 아니라 특정 팀원에게도 플레이어의 지위를 표시 할 수 있습니다.

이것을 모델링하고 풀 리더 보드를 검색하는 올바른/최선의 방법은 무엇입니까?

class Team < ActiveRecord::Base 
has_many :players, dependent: :destroy 
has_many :placements, through: :players 
has_many :pools, through: :team_pools 

class Placement < ActiveRecord::Base 
belongs_to :player 
attr_accessible :month, :player_id, :points, :position 

class Pool < ActiveRecord::Base 
has_many :teams, through: :team_pools 

class TeamPool < ActiveRecord::Base 
belongs_to :team 
belongs_to :pool 

@pool_leaderboard = ? 

답변

2
class Pool < ActiveRecord::Base 
has_many :teams, through: :team_pools 
has_many :placements, through => :teams 

@pool_leaderboard = @pool.placements.includes(:player).where(month: Date.today.beginning_of_month).order('points desc') 
관련 문제