forked from OpenNeo/impress
user#assign_closeted_to_items! now assigns when there are duplicates
This commit is contained in:
parent
513711bf60
commit
63bc0067c0
1 changed files with 11 additions and 6 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue