Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow #count through a has_many association to accept :include. [Dan …

…Peterson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4618 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 971e03f24e1121a2fe03beab23b0370a64fcfc37 1 parent 04d9e94
@technoweenie technoweenie authored
View
2  activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow #count through a has_many association to accept :include. [Dan Peterson]
+
* create_table rdoc: suggest :id => false for habtm join tables. [Zed Shaw]
* PostgreSQL: return array fields as strings. #4664 [Robby Russell]
View
1  activerecord/lib/active_record/associations.rb
@@ -17,7 +17,6 @@ def initialize(owner_class_name, reflection)
class HasManyThroughAssociationPolymorphicError < ActiveRecordError #:nodoc:
def initialize(owner_class_name, reflection, source_reflection)
- source_reflection = source_reflection
super("Cannot have a has_many :through association '#{owner_class_name}##{reflection.name}' on the polymorphic object '#{source_reflection.class_name}##{source_reflection.name}'.")
end
end
View
1  activerecord/lib/active_record/associations/has_many_association.rb
@@ -48,6 +48,7 @@ def count(*args)
options[:conditions] = options[:conditions].nil? ?
@finder_sql :
@finder_sql + " AND (#{sanitize_sql(options[:conditions])})"
+ options[:include] = @reflection.options[:include]
@reflection.klass.count(column_name, options)
end
View
4 activerecord/test/associations_go_eager_test.rb
@@ -356,4 +356,8 @@ def test_preconfigured_includes_with_has_many_and_habtm
assert_equal 2, one.comments.size
assert_equal 2, one.categories.size
end
+
+ def test_count_with_include
+ assert_equal 3, authors(:david).posts_with_comments.count(:conditions => "length(comments.body) > 15")
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.