aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-11-23 14:58:10 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-23 14:33:00 -0800
commitd33dcba72d19beffc4a359f2fb89659f24122e9a (patch)
tree1f72b6c88a6714ecc9fe9ac90cad5bd4ee0b65c8 /activerecord
parent0456feab1198456069d4b5a9da221e6fd818e3da (diff)
downloadrails-d33dcba72d19beffc4a359f2fb89659f24122e9a.tar.gz
rails-d33dcba72d19beffc4a359f2fb89659f24122e9a.tar.bz2
rails-d33dcba72d19beffc4a359f2fb89659f24122e9a.zip
Do not send id for quoting twice if the primary key is string.
[#6022 state:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb3
-rw-r--r--activerecord/test/cases/relations_test.rb9
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 32c7d08daa..7e2ce06dae 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -26,7 +26,8 @@ module ActiveRecord
when Range, Arel::Relation
attribute.in(value)
when ActiveRecord::Base
- attribute.eq(value.quoted_id)
+ sanitized_id = attribute.class == Arel::Attributes::String ? value.id : value.quoted_id
+ attribute.eq(sanitized_id)
when Class
# FIXME: I think we need to deprecate this behavior
attribute.eq(value.name)
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 535bcd4396..1682f34a1d 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -14,11 +14,18 @@ require 'models/bird'
require 'models/car'
require 'models/engine'
require 'models/tyre'
+require 'models/minivan'
class RelationTest < ActiveRecord::TestCase
fixtures :authors, :topics, :entrants, :developers, :companies, :developers_projects, :accounts, :categories, :categorizations, :posts, :comments,
- :tags, :taggings, :cars
+ :tags, :taggings, :cars, :minivans
+
+ def test_do_not_double_quote_string_id
+ van = Minivan.last
+ assert van
+ assert_equal van.id, Minivan.where(:minivan_id => van).to_a.first.minivan_id
+ end
def test_bind_values
relation = Post.scoped