我需要在Rails 3.2语法中编写一个SQL查询,其中包含:
" 向我提交属于visibility_private == false
"
Track.rb
has_many :missions
attr_accessible :visibility_private
Mission.rb
belongs_to :track
has_many :submissions
Submission.rb
belongs_to :mission
我最初的尝试就是这个,但那肯定是错的:
Submission.joins(:mission).where(:missions => { mission.track.visibility_private == false })
答案 0 :(得分:0)
你需要使用类似的东西,
Submission.joins(mission: :track).where("tracks.visibility_private = ?",false)
或
Submission.joins(mission: :track).where(tracks: { visibility_private: false })
希望这对你有用。
答案 1 :(得分:0)
尝试此代码
Submission.includes(mission: :track).where(tracks: { visibility_private: false })