Permalink
Browse files

Do not send id for quoting twice if the primary key is string.

[#6022 state:resolved]
  • Loading branch information...
1 parent 890d005 commit d67464a160bf2a5ef899a14cff93756aad374a6a Neeraj Singh committed with tenderlove Nov 23, 2010
@@ -31,7 +31,8 @@ def build_from_hash(attributes, default_table)
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)
@@ -13,11 +13,18 @@
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,
- :taggings, :cars
+ :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_two_named_scopes_with_includes_should_not_drop_any_include
car = Car.incl_engines.incl_tyres.first

0 comments on commit d67464a

Please sign in to comment.