lib/enumerate_by.rb in enumerate_by-0.4.1 vs lib/enumerate_by.rb in enumerate_by-0.4.2
- old
+ new
@@ -251,11 +251,14 @@
# Otherwise, any changes to that column remain there.
def bootstrap(*records)
uncached do
# Remove records that are no longer being used
records.flatten!
- delete_all(['id NOT IN (?)', records.map {|record| record[:id]}])
+ ids = records.map {|record| record[:id]}.compact
+ delete_all(ids.any? ? ['id NOT IN (?)', ids] : nil)
+
+ # Find remaining existing records (to be updated)
existing = all.inject({}) {|existing, record| existing[record.id] = record; existing}
records.map! do |attributes|
attributes.symbolize_keys!
defaults = attributes.delete(:defaults)
@@ -300,10 +303,11 @@
#
# See EnumerateBy::Bootstrapped#bootstrap for information about usage.
def fast_bootstrap(*records)
# Remove records that are no longer being used
records.flatten!
- delete_all(['id NOT IN (?)', records.map {|record| record[:id]}])
+ ids = records.map {|record| record[:id]}.compact
+ delete_all(ids.any? ? ['id NOT IN (?)', ids] : nil)
# Find remaining existing records (to be updated)
quoted_table_name = self.quoted_table_name
existing = connection.select_all("SELECT * FROM #{quoted_table_name}").inject({}) {|existing, record| existing[record['id'].to_i] = record; existing}