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

Ticket #11517: eager_include_with_order_on_aliased_table_name_and_limit.patch

File eager_include_with_order_on_aliased_table_name_and_limit.patch, 1.4 kB (added by jonathan_viney, 4 months ago)
  • test/cases/associations/eager_test.rb

    old new  
    177177    end 
    178178  end 
    179179 
     180  def test_eager_association_with_order_on_aliased_table_name_and_limit 
     181    Author.find(:first, :include => [:comments, :funky_comments], :order => 'funky_comments_authors.id', :limit => 1) 
     182  end 
     183 
    180184  def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations 
    181185    posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :order => 'posts.id') 
    182186    assert_equal 1, posts.length 
  • lib/active_record/associations.rb

    old new  
    14371437          sql << " FROM #{connection.quote_table_name table_name} " 
    14381438 
    14391439          if is_distinct 
    1440             sql << join_dependency.join_associations.reject{ |ja| !all_tables.include?(ja.table_name) }.collect(&:association_join).join 
     1440            sql << join_dependency.join_associations.reject{ |ja| !all_tables.include?(ja.aliased_table_name) }.collect(&:association_join).join 
    14411441            add_joins!(sql, options, scope) 
    14421442          end 
    14431443