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

Changeset 7328

Show
Ignore:
Timestamp:
08/16/07 04:58:45 (1 year ago)
Author:
nzkoz
Message:

Don't clobber :includes passed to count on has_many association. Closes #9175 [danger]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-stable/activerecord/CHANGELOG

    r7327 r7328  
    11*SVN* 
     2 
     3* Don't clobber includes passed to has_many.count [danger] 
    24 
    35* Make sure has_many uses :include when counting [danger] 
  • branches/1-2-stable/activerecord/lib/active_record/associations/has_many_association.rb

    r7327 r7328  
    5151            @finder_sql : 
    5252            @finder_sql + " AND (#{sanitize_sql(options[:conditions])})" 
    53           options[:include] = @reflection.options[:include] 
     53          options[:include] ||= @reflection.options[:include] 
    5454 
    5555          @reflection.klass.count(column_name, options) 
  • branches/1-2-stable/activerecord/test/associations/eager_test.rb

    r7327 r7328  
    168168    posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'") 
    169169    assert_equal 0, posts.size 
     170  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') 
    170176  end 
    171177