Class: GroupAssociatedGroup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GroupAssociatedGroup
- Defined in:
- app/models/group_associated_group.rb
Instance Method Summary collapse
Instance Method Details
#add_associated_users ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/models/group_associated_group.rb', line 9 def add_associated_users with_mutex do associated_group.users.in_batches do |users| users.each { |user| group.add_automatically(user, subject: associated_group.label) } end end end |
#remove_associated_users ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/group_associated_group.rb', line 17 def remove_associated_users with_mutex do User .where( "NOT EXISTS( SELECT 1 FROM user_associated_groups uag JOIN group_associated_groups gag ON gag.associated_group_id = uag.associated_group_id WHERE uag.user_id = users.id AND gag.id != :gag_id AND gag.group_id = :group_id )", gag_id: id, group_id: group_id, ) .in_batches do |users| users.each { |user| group.remove_automatically(user, subject: associated_group.label) } end end end |