class Users < ActiveRecord::Base
has_many :meetings, :through => :meeting_participations
has_many :meeting_participations
end
class Meetings < ActiveRe
The clean, associations way to do it is:
has_many :visible_meetings, -> { merge(MeetingParticipations.visible) },
:source => :meeting, :through => :meeting_participations
To put it in more generic terms: if you have a chained has_many
association you can scope the intermediate (through
) association via merging the scope. Probably requires Rails 4+.
Otherwise this would have to be done via creating a (probably unwanted) intermediate scoped association as seen in @Paul Pettengill's answer.
current_user.meetings.merge(MeetingParticipations.visible)