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

Ticket #9175: eager_count_performed_on_a_has_many_association_with_multi_table_conditional.diff

File eager_count_performed_on_a_has_many_association_with_multi_table_conditional.diff, 1.6 kB (added by danger, 3 years ago)
  • activerecord/test/associations/eager_test.rb

    old new  
    168168    posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'") 
    169169    assert_equal 0, posts.size 
    170170  end 
     171   
     172  def test_eager_count_performed_on_a_has_many_association_with_multi_table_conditional 
     173    author = authors(:david) 
     174    author_posts_without_comments = author.posts.select { |post| post.comments.blank? } 
     175    assert_equal author_posts_without_comments.size, author.posts.count(:all, :include => :comments, :conditions => 'comments.id is null') 
     176  end 
    171177 
    172178  def test_eager_with_has_and_belongs_to_many_and_limit 
    173179    posts = Post.find(:all, :include => :categories, :order => "posts.id", :limit => 3) 
  • activerecord/lib/active_record/associations/has_many_association.rb

    old new  
    3131          options[:conditions] = options[:conditions].nil? ? 
    3232            @finder_sql : 
    3333            @finder_sql + " AND (#{sanitize_sql(options[:conditions])})" 
    34           options[:include] = @reflection.options[:include] 
     34          options[:include] ||= @reflection.options[:include] 
    3535 
    3636          @reflection.klass.count(column_name, options) 
    3737        end