Skip to content

Commit

Permalink
Merge pull request #15651 from Ladas/make_sure_passed_ids_for_habtm_r…
Browse files Browse the repository at this point in the history
…elation_are_unique

Make sure passed ids for habtm relation are unique
  • Loading branch information
agrare authored Jul 31, 2017
2 parents ab91e89 + 0a3faf3 commit 36619c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/manager_refresh/inventory_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def attributes(inventory_collection_scope = nil)
data[key] = value.compact.map(&:load).compact
# We can use built in _ids methods to assign array of ids into has_many relations. So e.g. the :key_pairs=
# relation setter will become :key_pair_ids=
attributes_for_saving[key.to_s.singularize + "_ids"] = data[key].map(&:id).compact
attributes_for_saving[key.to_s.singularize + "_ids"] = data[key].map(&:id).compact.uniq
elsif loadable?(value) || inventory_collection_scope.association_to_foreign_key_mapping[key]
# Lets fill also the original data, so other InventoryObject referring to this attribute gets the right
# result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def initialize_data_and_inventory_collections
:flavor => @data[:flavors].lazy_find(flavor_data(1)[:name]),
:genealogy_parent => @data[:miq_templates].lazy_find(image_data(1)[:ems_ref]),
:key_pairs => [@data[:key_pairs].lazy_find(key_pair_data(1)[:name]),
@data[:key_pairs].lazy_find(key_pair_data(1)[:name]),
@data[:key_pairs].lazy_find(key_pair_data(12)[:name])],
:location => @data[:networks].lazy_find("#{vm_data(1)[:ems_ref]}__public",
:key => :hostname,
Expand Down

0 comments on commit 36619c7

Please sign in to comment.