mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 12:43:54 -06:00
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:
parent
84d4307b1c
commit
f955ec6018
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user