2012-04-28 113 views
0

我是新來的導軌和具有下列情況的應用程序的工作模式協會:的比賽

用戶有技能(如漂流,舞蹈) 用戶參與競賽 大賽測量多個技能 在每場比賽結束時,每個用戶都得分(例如跳舞:5,漂流:4)

什麼是建模的最佳方式?

感謝,

+0

不要忘了接受的答案 – 2012-04-29 01:20:08

回答

1

這讓討厭的:■在最後我居然不知道這是正確的方式

class Skill < ActiveRecord::Base 
    has_many :skill_scores 
    has_many :user_skills 
end 

class UserSkill < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :skill 
end 

class SkillScore < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :contest 
    belongs_to :skill 
end 

class User < ActiveRecord::Base 
    has_many :skills 
    has_many :contests, :through => :contest_participations 
    has_many :skill_scores 
end 

class Contest < ActiveRecord::Base 
    has_many :users, :through => :contest_participations 
    has_many :skill_scores 
end 

class ContestParticipation < ActiveRecord::Base 
    belongs_to :user 
    belongs_to :contest 
end