Class: UserAssociatedGroup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- UserAssociatedGroup
- Defined in:
- app/models/user_associated_group.rb
Instance Method Summary collapse
Instance Method Details
#add_to_associated_groups ⇒ Object
10 11 12 13 14 |
# File 'app/models/user_associated_group.rb', line 10 def add_to_associated_groups associated_group.groups.each do |group| group.add_automatically(user, subject: associated_group.label) end end |
#remove_from_associated_groups ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/user_associated_group.rb', line 16 def remove_from_associated_groups Group .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 = :user_id AND uag.id != :uag_id AND gag.group_id = groups.id )", uag_id: id, user_id: user_id, ) .each { |group| group.remove_automatically(user, subject: associated_group.label) } end |