Skip to content
This repository
Browse code

Merge pull request #1362 from sirlantis/patch-1

Unquoted query generated by through-association scope
  • Loading branch information...
commit f07fd69e5b2e4c59b523399a40204228d27a39fe 2 parents d756525 + d3cfb93
Aaron Patterson tenderlove authored
4 activerecord/lib/active_record/associations/through_association_scope.rb
@@ -30,7 +30,9 @@ def construct_conditions
30 30 # Associate attributes pointing to owner, quoted.
31 31 def construct_quoted_owner_attributes(reflection)
32 32 if as = reflection.options[:as]
33   - { "#{as}_id" => @owner[reflection.active_record_primary_key],
  33 + { "#{as}_id" => @owner.class.quote_value(
  34 + @owner[reflection.active_record_primary_key],
  35 + reflection.klass.columns_hash["#{as}_id"]),
34 36 "#{as}_type" => reflection.klass.quote_value(
35 37 @owner.class.base_class.name.to_s,
36 38 reflection.klass.columns_hash["#{as}_type"]) }
4 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -471,6 +471,10 @@ def test_count_has_many_through_with_named_scope
471 471 assert_equal 1, authors(:mary).categories.general.count
472 472 end
473 473
  474 + def test_has_many_through_on_new_record
  475 + assert_equal [], Post.new.tags.all
  476 + end
  477 +
474 478 def test_joining_has_many_through_belongs_to
475 479 posts = Post.joins(:author_categorizations).
476 480 where('categorizations.id' => categorizations(:mary_thinking_sti).id)

0 comments on commit f07fd69

Please sign in to comment.
Something went wrong with that request. Please try again.