Changeset 7347
- Timestamp:
- 08/20/07 04:26:10 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1-2-stable/activerecord/CHANGELOG
r7328 r7347 1 1 *SVN* 2 3 * Fix #count on a has_many :through association so that it recognizes the :uniq option. Closes #8801 [lifofifo] 2 4 3 5 * Don't clobber includes passed to has_many.count [danger] branches/1-2-stable/activerecord/lib/active_record/associations/has_many_through_association.rb
r6410 r7347 102 102 calculate(:sum, *args, &block) 103 103 end 104 105 def count(*args) 106 column_name, options = @reflection.klass.send(:construct_count_options_from_legacy_args, *args) 107 if @reflection.options[:uniq] 108 # This is needed becase 'SELECT count(DISTINCT *)..' is not valid sql statement. 109 column_name = "#{@reflection.klass.table_name}.#{@reflection.klass.primary_key}" if column_name == :all 110 options.merge!(:distinct => true) 111 end 112 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) } 113 end 104 114 105 115 protected branches/1-2-stable/activerecord/test/associations/join_model_test.rb
r6410 r7347 30 30 assert_equal 1, authors(:mary).unique_categorized_posts.size 31 31 end 32 32 33 def test_has_many_uniq_through_count 34 author = authors(:mary) 35 assert !authors(:mary).unique_categorized_posts.loaded? 36 assert_queries(1) { assert_equal 1, author.unique_categorized_posts.count } 37 assert_queries(1) { assert_equal 1, author.unique_categorized_posts.count(:title, {}) } 38 assert_queries(1) { assert_equal 0, author.unique_categorized_posts.count(:title, { :conditions => "title is NULL" }) } 39 assert !authors(:mary).unique_categorized_posts.loaded? 40 end 41 33 42 def test_polymorphic_has_many 34 43 assert posts(:welcome).taggings.include?(taggings(:welcome_general))