Use Rails 4.2+ API for typecasting on master

Note: this is still considered a private (internal) API on Rails side and is
subject to change in the future.
This commit is contained in:
Godfrey Chan 2014-08-17 18:46:53 -07:00
parent 84d4307b1c
commit f955ec6018

View File

@ -71,11 +71,20 @@ class SqlBuilder
#AS reloads this on tests #AS reloads this on tests
remove_const :FTYPE_MAP if defined? FTYPE_MAP remove_const :FTYPE_MAP if defined? FTYPE_MAP
if rails_master?
FTYPE_MAP = {
23 => ActiveRecord::Type::Integer.new,
1114 => ActiveRecord::Type::DateTime.new,
16 => ActiveRecord::Type::Boolean.new
}
else
FTYPE_MAP = { FTYPE_MAP = {
23 => :value_to_integer, 23 => :value_to_integer,
1114 => :string_to_time, 1114 => :string_to_time,
16 => :value_to_boolean 16 => :value_to_boolean
} }
end
def self.map_exec(klass, sql, args = {}) def self.map_exec(klass, sql, args = {})
self.new(sql).map_exec(klass, args) self.new(sql).map_exec(klass, args)
@ -93,8 +102,12 @@ class SqlBuilder
setters.each_with_index do |mapper, index| setters.each_with_index do |mapper, index|
translated = row[index] translated = row[index]
if mapper[1] && !translated.nil? if mapper[1] && !translated.nil?
if rails_master?
translated = mapper[1].type_cast_from_database(translated)
else
translated = ActiveRecord::ConnectionAdapters::Column.send mapper[1], translated translated = ActiveRecord::ConnectionAdapters::Column.send mapper[1], translated
end end
end
mapped.send mapper[0], translated mapped.send mapper[0], translated
end end
mapped mapped