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

Ticket #6778: fix_6778.patch

File fix_6778.patch, 1.9 kB (added by jonathan_viney, 2 years ago)
  • test/finder_test.rb

    old new  
    442442        :conditions => "posts.id <= 3 OR posts.#{QUOTED_TYPE} = 'Post'") 
    443443    end 
    444444  end 
     445   
     446  def test_find_ignores_previously_inserted_record 
     447    post = Post.create! 
     448    assert_equal [], Post.find(:all, :conditions => 'id is null') 
     449  end 
    445450 
    446451  def test_find_by_empty_ids 
    447452    assert_equal [], Post.find([]) 
  • lib/active_record/connection_adapters/mysql_adapter.rb

    old new  
    387387          end 
    388388          @connection.real_connect(*@connection_options) 
    389389          execute("SET NAMES '#{encoding}'") if encoding 
     390           
     391          # By default, MySQL will find the id of the last inserted row when doing 
     392          # a SELECT with conditions such as "id is null". Turn off this unwanted behaviour. 
     393          # http://dev.rubyonrails.org/ticket/6778 
     394          execute("SET SQL_AUTO_IS_NULL=0") 
    390395        end 
    391396 
    392397        def select(sql, name = nil) 
  • CHANGELOG

    old new  
    11*SVN* 
    22 
     3* Set variable on MySQL connection to ignore recently inserted records when querying with 'id is null'. Closes #6778 [Jonathan Viney] 
     4 
    35* Consolidated different create and create! versions to call through to the base class with scope. This fixes inconsistencies, especially related to protected attribtues. Closes #5847 [Alexander Dymo, Tobias Luetke] 
    46 
    57* find supports :lock with :include. Check whether your database allows SELECT ... FOR UPDATE with outer joins before using.  #6764 [vitaly, Jeremy Kemper]