Scope with join on :has_many :through association

前端 未结 8 1630
孤城傲影
孤城傲影 2020-11-30 19:14
class Users < ActiveRecord::Base
  has_many :meetings, :through => :meeting_participations
  has_many :meeting_participations
end

class Meetings < ActiveRe         


        
8条回答
  •  渐次进展
    2020-11-30 19:48

    This is my solution for your problem:

    class User < ActiveRecord::Base
      has_many :meeting_participations
      has_many :meetings, :through => :meeting_participations do
       def visible
         where("meeting_participations.visible = ?", true)
       end
      end
    end
    

    @user.meetings.visible

提交回复
热议问题