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

Ticket #5863: select_accepts_array.patch

File select_accepts_array.patch, 1.6 kB (added by veader, 5 months ago)
  • test/cases/base_test.rb

    old new  
    18391839    assert_equal %(#<Topic id: 1>), Topic.find(:first, :select => 'id', :conditions => 'id = 1').inspect 
    18401840    assert_equal %(#<Topic id: 1, title: "The First Topic">), Topic.find(:first, :select => 'id, title', :conditions => 'id = 1').inspect 
    18411841  end 
     1842   
     1843  def test_inspect_limited_select_instance_with_array 
     1844    assert_equal %(#<Topic id: 1, title: "The First Topic">), Topic.find(:first, :select => [:id, :title], :conditions => 'id = 1').inspect 
     1845  end 
    18421846 
    18431847  def test_inspect_class_without_table 
    18441848    assert_equal "NonExistentTable(Table doesn't exist)", NonExistentTable.inspect 
  • lib/active_record/base.rb

    old new  
    13651365 
    13661366        def construct_finder_sql(options) 
    13671367          scope = scope(:find) 
    1368           sql  = "SELECT #{(scope && scope[:select]) || options[:select] || (options[:joins] && quoted_table_name + '.*') || '*'} " 
     1368          select_items = (scope && scope[:select]) || options[:select] 
     1369          select_items = select_items.join(',') if select_items && select_items.respond_to?(:join) 
     1370          sql  = "SELECT #{select_items || (options[:joins] && quoted_table_name + '.*') || '*'} " 
    13691371          sql << "FROM #{(scope && scope[:from]) || options[:from] || quoted_table_name} " 
    13701372 
    13711373          add_joins!(sql, options, scope)