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

Changeset 8856

Show
Ignore:
Timestamp:
02/11/08 02:50:58 (5 months ago)
Author:
nzkoz
Message:

Fix eager loading with pre-quoted table names. Closes #11046 [danielmorrison, Koz, Jeremy Kemper]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/lib/active_record/associations.rb

    r8790 r8856  
    13801380          end 
    13811381          return false unless conditions.any? 
    1382           conditions.join(' ').scan(/([\.\w]+)\.\w+/).flatten.any? do |condition_table_name| 
     1382          conditions.join(' ').scan(/([\.\w]+).?\./).flatten.any? do |condition_table_name| 
    13831383            condition_table_name != table_name 
    13841384          end 
     
    13891389          order = options[:order] 
    13901390          return false unless order 
    1391           order.to_s.scan(/([\.\w]+)\.\w+/).flatten.any? do |order_table_name| 
     1391          order.to_s.scan(/([\.\w]+).?\./).flatten.any? do |order_table_name| 
    13921392            order_table_name != table_name 
    13931393          end 
  • trunk/activerecord/test/cases/associations/eager_test.rb

    r8762 r8856  
    118118    assert_equal 3, comments.length 
    119119    assert_equal [6,7,8], comments.collect { |c| c.id } 
     120  end 
     121 
     122  def test_eager_association_loading_with_belongs_to_and_conditions_string_with_unquoted_table_name 
     123    assert_nothing_raised do 
     124      Comment.find(:all, :include => :post, :conditions => ['posts.id = ?',4]) 
     125    end 
     126  end 
     127 
     128  def test_eager_association_loading_with_belongs_to_and_conditions_string_with_quoted_table_name 
     129    assert_nothing_raised do 
     130      Comment.find(:all, :include => :post, :conditions => ["#{Comment.connection.quote_table_name('posts.id')} = ?",4]) 
     131    end 
     132  end 
     133 
     134  def test_eager_association_loading_with_belongs_to_and_order_string_with_unquoted_table_name 
     135    assert_nothing_raised do 
     136      Comment.find(:all, :include => :post, :order => 'posts.id') 
     137    end 
     138  end 
     139 
     140  def test_eager_association_loading_with_belongs_to_and_order_string_with_quoted_table_name 
     141    assert_nothing_raised do 
     142      Comment.find(:all, :include => :post, :order => Comment.connection.quote_table_name('posts.id')) 
     143    end 
    120144  end 
    121145