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

Changeset 3240

Show
Ignore:
Timestamp:
12/08/05 04:44:54 (3 years ago)
Author:
david
Message:

Fixed that using :include together with :conditions array in Base.find would cause NoMethodError (closes #2887) [Paul Hammmond]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r3235 r3240  
    11*SVN* 
     2 
     3* Fixed that using :include together with :conditions array in Base.find would cause NoMethodError #2887 [Paul Hammmond] 
    24 
    35* PostgreSQL: more robust sequence name discovery.  #3087 [Rick Olson] 
  • trunk/activerecord/lib/active_record/associations.rb

    r3213 r3240  
    10301030 
    10311031        def include_eager_conditions?(options) 
    1032           return false unless options[:conditions] 
    1033            
    1034           options[:conditions].scan(/ ([^.]+)\.[^.]+ /).flatten.any? do |condition_table_name|  
     1032          conditions = options[:conditions] 
     1033          return false unless conditions 
     1034          conditions = conditions.first if conditions.is_a?(Array) 
     1035          conditions.scan(/(\w+)\.\w+/).flatten.any? do |condition_table_name| 
    10351036            condition_table_name != table_name 
    10361037          end 
  • trunk/activerecord/test/associations_go_eager_test.rb

    r3051 r3240  
    8484  end 
    8585   
     86  def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions_array 
     87    comments = Comment.find(:all, :include => :post, :conditions => ['post_id = ?',4], :limit => 3, :offset => 1, :order => 'comments.id') 
     88    assert_equal 3, comments.length 
     89    assert_equal [6,7,8], comments.collect { |c| c.id } 
     90  end 
     91 
    8692  def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations 
    8793    posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1) 
     
    100106    assert_equal 2, posts.size 
    101107    assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size } 
     108  end 
     109 
     110  def test_eager_with_has_many_and_limit_and_conditions 
     111    posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.body = 'hello'", :order => "posts.id") 
     112    assert_equal 2, posts.size 
     113    assert_equal [4,5], posts.collect { |p| p.id } 
     114  end 
     115 
     116  def test_eager_with_has_many_and_limit_and_conditions_array 
     117    posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "posts.body = ?", 'hello' ], :order => "posts.id") 
     118    assert_equal 2, posts.size 
     119    assert_equal [4,5], posts.collect { |p| p.id }     
     120  end 
     121 
     122  def test_eager_with_has_many_and_limit_and_conditions_array_on_the_eagers 
     123    assert_raises(ArgumentError) do 
     124      posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => [ "authors.name = ?", 'David' ]) 
     125    end 
    102126  end 
    103127