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,9 +52,13 @@ 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]
|
||||||
|
items.each do |item|
|
||||||
if hanger.owned?
|
if hanger.owned?
|
||||||
item.owned = true
|
item.owned = true
|
||||||
else
|
else
|
||||||
|
@ -62,6 +66,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def closet_hangers_groups_visible_to(user)
|
def closet_hangers_groups_visible_to(user)
|
||||||
return [true, false] if user == self
|
return [true, false] if user == self
|
||||||
|
|
Loading…
Reference in a new issue