1
0
Fork 0
forked from OpenNeo/impress

user#assign_closeted_to_items! now assigns when there are duplicates

This commit is contained in:
Emi Matchu 2011-08-03 10:18:03 -04:00
parent 513711bf60
commit 63bc0067c0

View file

@ -52,13 +52,18 @@ class User < ActiveRecord::Base
# N^2 searching the items list for items that match the given IDs or vice # N^2 searching the items list for items that match the given IDs or vice
# versa, and everything stays a lovely O(n) # versa, and everything stays a lovely O(n)
items_by_id = {} items_by_id = {}
items.each { |item| items_by_id[item.id] = item } items.each do |item|
items_by_id[item.id] ||= []
items_by_id[item.id] << item
end
closet_hangers.where(:item_id => items_by_id.keys).each do |hanger| closet_hangers.where(:item_id => items_by_id.keys).each do |hanger|
item = items_by_id[hanger.item_id] items = items_by_id[hanger.item_id]
if hanger.owned? items.each do |item|
item.owned = true if hanger.owned?
else item.owned = true
item.wanted = true else
item.wanted = true
end
end end
end end
end end