From 04c2d2e2e4197a1564c33f09d3e52253d845925f Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Wed, 6 Feb 2013 13:19:09 -0500 Subject: active_record: Quote numeric values compared to string columns. --- activerecord/lib/active_record/relation/predicate_builder.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activerecord/lib/active_record/relation/predicate_builder.rb') diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index b31fdfd981..5f311ed6d4 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -51,6 +51,10 @@ module ActiveRecord when Class # FIXME: I think we need to deprecate this behavior attribute.eq(value.name) + when Integer, ActiveSupport::Duration + # Arel treats integers as literals, but they should be quoted when compared with strings + column = engine.connection.schema_cache.columns_hash(table.name)[attribute.name.to_s] + attribute.eq(Arel::Nodes::SqlLiteral.new(engine.connection.quote(value, column))) else attribute.eq(value) end -- cgit v1.2.3