Changeset 7199
- Timestamp:
- 07/20/07 00:10:06 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r7192 r7199 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 * Fix and properly document/test count(column_name) usage. Closes #8999 [lifofifo] trunk/activerecord/lib/active_record/associations/has_many_through_association.rb
r7182 r7199 101 101 calculate(:sum, *args, &block) 102 102 end 103 104 def count(*args) 105 column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args) 106 if @reflection.options[:uniq] 107 # This is needed becase 'SELECT count(DISTINCT *)..' is not valid sql statement. 108 column_name = "#{@reflection.klass.table_name}.#{@reflection.klass.primary_key}" if column_name == :all 109 options.merge!(:distinct => true) 110 end 111 @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(column_name, options) } 112 end 103 113 104 114 protected trunk/activerecord/test/associations/join_model_test.rb
r7182 r7199 31 31 assert_equal 1, authors(:mary).unique_categorized_posts.size 32 32 end 33 33 34 def test_has_many_uniq_through_count 35 author = authors(:mary) 36 assert !authors(:mary).unique_categorized_posts.loaded? 37 assert_queries(1) { assert_equal 1, author.unique_categorized_posts.count } 38 assert_queries(1) { assert_equal 1, author.unique_categorized_posts.count(:title) } 39 assert_queries(1) { assert_equal 0, author.unique_categorized_posts.count(:title, :conditions => "title is NULL") } 40 assert !authors(:mary).unique_categorized_posts.loaded? 41 end 42 34 43 def test_polymorphic_has_many 35 44 assert posts(:welcome).taggings.include?(taggings(:welcome_general))