Browse files

string IDs are now quoted correctly [#5064 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 44e7fba commit b520d602ffb85f3816f4407ff9dd5c7721a2da7d @wsc wsc committed with josevalim Jul 10, 2010
View
2 activerecord/lib/active_record/associations/through_association_scope.rb
@@ -35,7 +35,7 @@ def construct_quoted_owner_attributes(reflection)
@owner.class.base_class.name.to_s,
reflection.klass.columns_hash["#{as}_type"]) }
elsif reflection.macro == :belongs_to
- { reflection.klass.primary_key => @owner[reflection.primary_key_name] }
+ { reflection.klass.primary_key => @owner.class.quote_value(@owner[reflection.primary_key_name]) }
else
{ reflection.primary_key_name => owner_quoted_id }
end
View
12 activerecord/test/cases/associations/has_one_through_associations_test.rb
@@ -6,9 +6,12 @@
require 'models/sponsor'
require 'models/organization'
require 'models/member_detail'
+require 'models/minivan'
+require 'models/dashboard'
+require 'models/speedometer'
class HasOneThroughAssociationsTest < ActiveRecord::TestCase
- fixtures :member_types, :members, :clubs, :memberships, :sponsors, :organizations
+ fixtures :member_types, :members, :clubs, :memberships, :sponsors, :organizations, :minivans, :dashboards, :speedometers
def setup
@member = members(:groucho)
@@ -202,4 +205,11 @@ def test_save_of_record_with_loaded_has_one_through
Club.find(@club.id, :include => :sponsored_member).save!
end
end
+
+ def test_value_is_properly_quoted
+ minivan = Minivan.find('m1')
+ assert_nothing_raised do
+ minivan.dashboard
+ end
+ end
end
View
3 activerecord/test/fixtures/dashboards.yml
@@ -0,0 +1,3 @@
+cool_first:
+ dashboard_id: d1
+ name: my_dashboard
View
4 activerecord/test/fixtures/minivans.yml
@@ -0,0 +1,4 @@
+cool_first:
+ minivan_id: m1
+ name: my_minivan
+ speedometer_id: s1
View
4 activerecord/test/fixtures/speedometers.yml
@@ -0,0 +1,4 @@
+cool_first:
+ speedometer_id: s1
+ name: my_speedometer
+ dashboard_id: d1
View
3 activerecord/test/models/dashboard.rb
@@ -0,0 +1,3 @@
+class Dashboard < ActiveRecord::Base
+ set_primary_key :dashboard_id
+end
View
6 activerecord/test/models/minivan.rb
@@ -0,0 +1,6 @@
+class Minivan < ActiveRecord::Base
+ set_primary_key :minivan_id
+
+ belongs_to :speedometer
+ has_one :dashboard, :through => :speedometer
+end
View
4 activerecord/test/models/speedometer.rb
@@ -0,0 +1,4 @@
+class Speedometer < ActiveRecord::Base
+ set_primary_key :speedometer_id
+ belongs_to :dashboard
+end
View
17 activerecord/test/schema/schema.rb
@@ -164,6 +164,11 @@ def create_table(*args, &block)
t.string :address_country
t.string :gps_location
end
+
+ create_table :dashboards, :force => true, :id => false do |t|
+ t.string :dashboard_id
+ t.string :name
+ end
create_table :developers, :force => true do |t|
t.string :name
@@ -290,6 +295,12 @@ def create_table(*args, &block)
t.boolean :favourite
t.integer :lock_version, :default => 0
end
+
+ create_table :minivans, :force => true, :id => false do |t|
+ t.string :minivan_id
+ t.string :name
+ t.string :speedometer_id
+ end
create_table :minimalistics, :force => true do |t|
end
@@ -452,6 +463,12 @@ def create_table(*args, &block)
t.string :name
t.integer :ship_id
end
+
+ create_table :speedometers, :force => true, :id => false do |t|
+ t.string :speedometer_id
+ t.string :name
+ t.string :dashboard_id
+ end
create_table :sponsors, :force => true do |t|
t.integer :club_id

0 comments on commit b520d60

Please sign in to comment.