From 63bc0067c03891d166f807f674ccb31523636192 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 3 Aug 2011 10:18:03 -0400 Subject: [PATCH] user#assign_closeted_to_items! now assigns when there are duplicates --- app/models/user.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 12ffecbf..a96f3efa 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,13 +52,18 @@ class User < ActiveRecord::Base # N^2 searching the items list for items that match the given IDs or vice # versa, and everything stays a lovely O(n) 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| - item = items_by_id[hanger.item_id] - if hanger.owned? - item.owned = true - else - item.wanted = true + items = items_by_id[hanger.item_id] + items.each do |item| + if hanger.owned? + item.owned = true + else + item.wanted = true + end end end end