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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -