我想写一个范围来显示一个范围内的用户
有人可以告诉我这是怎么写的。"Management Group"
或"Event Management Group"
我可以通过写下面的范围成功地在“管理组”中显示用户:
user.rb
scope :hosts, ->() { joins(:category_managementgroup).where('category_managementgroups.name' => "Management Group") }
我如何编写一个在“管理”中显示用户的范围 集团“和”活动管理小组“
我试过以下但不起作用:
scope :hosts, ->() { joins(:category_managementgroup).where('category_managementgroups.name' => "Event Management Group") && joins(:category_managementgroup).where('category_managementgroups.name' => "Management Group") }
我也试过以下但没有运气:
scope :hosts, ->() { joins(:category_managementgroup).where('category_managementgroups.name ? OR', "Event Management Group", "Management Group") }
非常感谢您的帮助
答案 0 :(得分:1)
你应该打破其他范围
User.rb
scope :hosts_in_any_management, -> { joins(:category_managementgroup).merge(CategoryMangagementgroup.in_management)}
scope :hosts_in_both_management_groups, -> { joins(:category_managementgroup).merge(CategoryMangagementgroup.both_management_groups) }
CategoryManagementgroup.rb
scope :in_management, -> { management_group.or(CategoryManagementgroup.event_management_group) }
scope :both_management_groups, -> { event_management_group.management_group }
scope :event_management_group, -> { where name: 'Event Management Group'}
scope :management_group, -> { where name: 'Management Group' }