Skip to content

Commit

Permalink
[ActsAsMiqSet] Have add_member track new members
Browse files Browse the repository at this point in the history
The previous implementation of `.add_member`, the `RelationshipMixin`
would keep track of the newly added members, and the new implementation
did not.

This was used once or twice in a controller validation, so putting the
return style back in place to keep the same interface and fix tests.
  • Loading branch information
NickLaMuro committed Jul 13, 2021
1 parent 7394506 commit 68338ad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/extensions/ar_miq_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def remove_all_members
alias remove_all_children remove_all_members

def add_members(*members)
added = []

transaction do
existing = miq_set_memberships.index_by { |ms| [ms.member_type, ms.member_id] }

Expand All @@ -140,8 +142,11 @@ def add_members(*members)
next if existing.include?([member.class.base_class.name, member.id])

miq_set_memberships.create!(:member => member)
added << member
end
end

added
end
alias add_children add_members
alias add_member add_members
Expand Down

0 comments on commit 68338ad

Please sign in to comment.