aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb1
-rw-r--r--activerecord/lib/active_record/associations/has_many_association.rb1
-rw-r--r--activerecord/test/associations_go_eager_test.rb4
4 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index d34cf3d2d6..df012b91ca 100644
--- a/activerecord/CHANGELOG
+++ b/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]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 5eb6495b9d..192c7b7a5f 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -17,7 +17,6 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/associations/has_many_association.rb b/activerecord/lib/active_record/associations/has_many_association.rb
index d00ac96540..e79fa858c4 100644
--- a/activerecord/lib/active_record/associations/has_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_association.rb
@@ -48,6 +48,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb
index d2ae4e0dd9..ddcd72d045 100644
--- a/activerecord/test/associations_go_eager_test.rb
+++ b/activerecord/test/associations_go_eager_test.rb
@@ -356,4 +356,8 @@ class EagerAssociationTest < Test::Unit::TestCase
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