【发布时间】:2013-05-08 15:54:26
【问题描述】:
在我的应用程序中有Athletes...运动员可以有很多运动。
运动员:
has_many :sports, :through => :user_sports
has_one :primary_sport, conditions: ["user_sports.primary = ?", true], class_name: "Sport"
has_many :user_sports
用户运动:
class UserSport < ActiveRecord::Base
attr_accessible :athlete_id, :sport_id, :primary
belongs_to :athlete
belongs_to :sport
end
我试图能够将 primary_sport 作为 Sport 对象而不是 user_sport 对象拉回。
【问题讨论】: