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

Ticket #8801: hmt_collection_count_uniq.patch

File hmt_collection_count_uniq.patch, 1.2 kB (added by lifofifo, 2 years ago)

has_many :through collections.count for :uniq => true

  • activerecord/test/associations/join_model_test.rb

    old new  
    2929  def test_has_many_uniq_through_join_model 
    3030    assert_equal 2, authors(:mary).categorized_posts.size 
    3131    assert_equal 1, authors(:mary).unique_categorized_posts.size 
     32    assert_equal 1, authors(:mary).unique_categorized_posts.count 
    3233  end 
    3334 
    3435  def test_polymorphic_has_many 
  • activerecord/lib/active_record/associations/has_many_through_association.rb

    old new  
    9999      def sum(*args, &block) 
    100100        calculate(:sum, *args, &block) 
    101101      end 
     102       
     103      def count(*args) 
     104        (@reflection.options[:uniq] ? load_target.size : @reflection.klass.send(:with_scope, construct_scope) { @reflection.klass.count(*args) })  
     105      end 
    102106 
    103107      protected 
    104108        def method_missing(method, *args, &block)