has one - Rails has_one with join table -
in app there athletes
... athletes can have many sports.
athlete:
has_many :sports, :through => :user_sports has_one :primary_sport, conditions: ["user_sports.primary = ?", true], class_name: "sport" has_many :user_sports
usersport:
class usersport < activerecord::base attr_accessible :athlete_id, :sport_id, :primary belongs_to :athlete belongs_to :sport end
i trying able pull primary_sport
sport object instead of user_sport
object.
since pull sports objects :through user_sports, should pull primary_sport object :through user_sports well.
has_one :primary_sport, :through => :user_sports, conditions: ["user_sports.primary = ?", true], class_name: "sport"
Comments
Post a Comment