Permalink
Browse files

Merge pull request #1362 from sirlantis/patch-1

Unquoted query generated by through-association scope
  • Loading branch information...
2 parents d756525 + d3cfb93 commit f07fd69e5b2e4c59b523399a40204228d27a39fe @tenderlove tenderlove committed May 29, 2011
View
4 activerecord/lib/active_record/associations/through_association_scope.rb
@@ -30,7 +30,9 @@ def construct_conditions
# Associate attributes pointing to owner, quoted.
def construct_quoted_owner_attributes(reflection)
if as = reflection.options[:as]
- { "#{as}_id" => @owner[reflection.active_record_primary_key],
+ { "#{as}_id" => @owner.class.quote_value(
+ @owner[reflection.active_record_primary_key],
+ reflection.klass.columns_hash["#{as}_id"]),
"#{as}_type" => reflection.klass.quote_value(
@owner.class.base_class.name.to_s,
reflection.klass.columns_hash["#{as}_type"]) }
View
4 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -471,6 +471,10 @@ def test_count_has_many_through_with_named_scope
assert_equal 1, authors(:mary).categories.general.count
end
+ def test_has_many_through_on_new_record
+ assert_equal [], Post.new.tags.all
+ end
+
def test_joining_has_many_through_belongs_to
posts = Post.joins(:author_categorizations).
where('categorizations.id' => categorizations(:mary_thinking_sti).id)

0 comments on commit f07fd69

Please sign in to comment.