aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/table_metadata.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-26 15:33:57 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-26 15:33:57 -0700
commit3179b4a868c370bf879c15c53b78f25fadec9b41 (patch)
tree5f8fa85b609f182cfbb9c2d4985c93a981208c2a /activerecord/lib/active_record/table_metadata.rb
parenta60770d3bf3a8aeac16c110f3a7d05a6d52a86d6 (diff)
downloadrails-3179b4a868c370bf879c15c53b78f25fadec9b41.tar.gz
rails-3179b4a868c370bf879c15c53b78f25fadec9b41.tar.bz2
rails-3179b4a868c370bf879c15c53b78f25fadec9b41.zip
Perform casting of single values within the predicate builder
As part of the larger refactoring to remove type casting from Arel, we need to do the casting of values eagerly. The predicate builder is the closest place that knows about the Active Record class, and can therefore have the type information. /cc @mrgilman [Sean Griffin & Melanie Gilman]
Diffstat (limited to 'activerecord/lib/active_record/table_metadata.rb')
-rw-r--r--activerecord/lib/active_record/table_metadata.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/table_metadata.rb b/activerecord/lib/active_record/table_metadata.rb
index bf705d3565..811e6964a9 100644
--- a/activerecord/lib/active_record/table_metadata.rb
+++ b/activerecord/lib/active_record/table_metadata.rb
@@ -8,6 +8,12 @@ module ActiveRecord
@association = association
end
+ def type_cast_for_database(attribute_name, value)
+ return value if value.is_a?(Arel::Nodes::BindParam) || klass.nil?
+ type = klass.type_for_attribute(attribute_name.to_s)
+ Arel::Nodes::Quoted.new(type.type_cast_for_database(value))
+ end
+
def resolve_column_aliases(hash)
hash = hash.dup
hash.keys.grep(Symbol) do |key|