FIX: Prevent cast error when import_id contains strings and numbers

Some importers insert numbers and strings as import_id into the same
custom_fields table. This change prevents cast errors during imports.
This commit is contained in:
Gerhard Schlager 2015-09-30 16:38:06 +02:00
parent 0f7aaf5ab1
commit 29d27ec2ef
1 changed files with 1 additions and 6 deletions

View File

@ -198,12 +198,7 @@ class ImportScripts::Base
return false if import_ids.empty?
existing = "#{type.to_s.classify}CustomField".constantize.where(name: 'import_id')
if Fixnum === import_ids.first
existing = existing.where('cast(value as int) in (?)', import_ids)
else
existing = existing.where('value in (?)', import_ids)
end
existing = existing.where('value in (?)', import_ids.map(&:to_s))
if existing.count == import_ids.length
# puts "Skipping #{import_ids.length} already imported #{type}"