0
我試圖運行下面的代碼:使用GROUP_BY找到重複數據刪除的記錄
dupe_groups = Activity.all.group_by { |e| e.non_id_attributes }.select{ |gr| gr.last.size > 1 }
redundant_elements = dupe_groups.map { |group| group.last - [group.last.first] }.flatten
redundant_elements.each(&:destroy)
不過,我得到以下錯誤:
Activity.find(:all).group_by { |e| e.non_id_attributes }.select{ |gr| gr.last.size > 1 }
NoMethodError: undefined method `last' for #<Hash:0x00000107e505e8>
from (irb):10:in `block in irb_binding'
from (irb):10:in `select'
from (irb):10
from /usr/local/bin/irb:12:in `<main>'
我怎樣才能得到這個傢伙的工作?
試圖刪除重複記錄 – keruilin 2011-05-25 03:52:34