class Users < ActiveRecord::Base
has_many :meetings, :through => :meeting_participations
has_many :meeting_participations
end
class Meetings < ActiveRecord::Base
has_many :users, :through => :meeting_participations
has_many :meeting_participations
end
class MeetingParticipations < ActiveRecord::Base
belongs_to :user
belongs_to :meeting
scope :hidden, where(:hidden => true)
scope :visible, where(:hidden => false)
end
hidden是m2m关联表中的一个额外的布尔列。鉴于某些Users情况current_user,我想做
current_user.meetings.visible
它将检索Meetings该hidden列所在的用户是其参与者的集合false。我得到的最接近的是将以下范围添加到Meetings类中
scope :visible, joins(:meeting_participations) & MeetingParticipation.visible
在scope不过滤Meetings对MeetingParticipations表,但有没有加入/条件对MeetingParticipations相关表格current_user。
与此问题是,如果current_user和another_user是两个参与者对于一些Meetings例如,Meetings结果集中的记录将针对已每个参与者返回hidden设置false。如果current_user已true设置hidden为所有Meetings,如果another_user在任何一个具有相同的会议的参与者hidden设置为false,那些Meetings将出现在Meetings.visible结果集。
是否可以有一个如上所述的作用域,该作用域可以正确地加入User实例?如果没有,有人可以推荐解决方案吗?