diff options
author | Michael Koziarski <michael@koziarski.com> | 2008-01-27 02:41:55 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2008-01-27 02:41:55 +0000 |
commit | 9500ad5fbc337d881dc953631f6d808ad08774c1 (patch) | |
tree | 368267c053dc6d0c18c0c0a04d76bcdd6bcf9292 /activerecord/lib/active_record/associations/has_many_through_association.rb | |
parent | f11904ad6d0d9981dfb54b8fe07bfa908607db35 (diff) | |
download | rails-9500ad5fbc337d881dc953631f6d808ad08774c1.tar.gz rails-9500ad5fbc337d881dc953631f6d808ad08774c1.tar.bz2 rails-9500ad5fbc337d881dc953631f6d808ad08774c1.zip |
Make sure count works on has_many :through associations using :group. Closes #10480 [remvee]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8742 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations/has_many_through_association.rb')
-rw-r--r-- | activerecord/lib/active_record/associations/has_many_through_association.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 1ca44d645c..96d0b73da2 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -124,6 +124,15 @@ module ActiveRecord column_name = "#{@reflection.quoted_table_name}.#{@reflection.klass.primary_key}" if column_name == :all options.merge!(:distinct => true) end + + if @reflection.options[:group] + unless column_name == :all + raise HasManyThroughCantCountOnColumnForGroupedAssociation.new(@owner, @reflection, column_name) + end + column_name = @reflection.options[:group] + options.merge!(:distinct => true) + end + @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) } end |