Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8801: 1-2-stable.diff

File 1-2-stable.diff, 2.1 kB (added by court3nay, 1 year ago)

re-patched for STABLE

  • activerecord/test/associations/join_model_test.rb

    old new  
    2929    assert_equal 2, authors(:mary).categorized_posts.size 
    3030    assert_equal 1, authors(:mary).unique_categorized_posts.size 
    3131  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   
    3342  def test_polymorphic_has_many 
    3443    assert posts(:welcome).taggings.include?(taggings(:welcome_general)) 
    3544  end 
  • activerecord/lib/active_record/associations/has_many_through_association.rb

    old new  
    101101      def sum(*args, &block) 
    102102        calculate(:sum, *args, &block) 
    103103      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 
    104114 
    105115      protected 
    106116        def method_missing(method, *args, &block)