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

Changeset 488

Show
Ignore:
Timestamp:
01/24/05 13:02:50 (4 years ago)
Author:
david
Message:

Fixed that the dynamic finders didnt treat nil as a "IS NULL" but rather "= NULL" case #515 [Demetrius]

Files:

Legend:

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

    r485 r488  
    11*SVN* 
     2 
     3* Fixed that the dynamic finders didn't treat nil as a "IS NULL" but rather "= NULL" case #515 [Demetrius] 
    24 
    35* Added bind-named arrays for interpolating a group of ids or strings in conditions #528 [bitsweat] 
  • trunk/activerecord/lib/active_record/base.rb

    r485 r488  
    669669            finder, attributes = ($1 == "all_by" ? :find_all : :find_first), $2.split("_and_") 
    670670            attributes.each { |attr_name| super unless column_methods_hash[attr_name.intern] } 
    671             conditions = attributes.collect { |attr_name| "#{attr_name} = ? "}.join(" AND ") 
     671 
     672            attr_index = -1 
     673            conditions = attributes.collect { |attr_name| attr_index += 1; "#{attr_name} #{arguments[attr_index] ? "=" : "IS"} ? " }.join(" AND ") 
    672674            send(finder, [conditions, *arguments[0...attributes.length]], *arguments[attributes.length..-1]) 
    673675          else 
  • trunk/activerecord/test/finder_test.rb

    r485 r488  
    193193 
    194194    assert_equal [], Topic.find_all_by_title("The First Topic!!") 
     195  end 
     196   
     197  def test_find_by_nil_attribute 
     198    topic = Topic.find_by_last_read nil 
     199    assert_not_nil topic 
     200    assert_nil topic.last_read 
     201  end 
     202   
     203  def test_find_all_by_nil_attribute 
     204    topics = Topic.find_all_by_last_read nil 
     205    assert_equal 1, topics.size 
     206    assert_nil topics[0].last_read 
     207  end 
     208   
     209  def test_find_by_nil_and_not_nil_attributes 
     210    topic = Topic.find_by_last_read_and_author_name nil, "Mary" 
     211    assert_equal "Mary", topic.author_name 
     212  end 
     213 
     214  def test_find_all_by_nil_and_not_nil_attributes 
     215    topics = Topic.find_all_by_last_read_and_author_name nil, "Mary" 
     216    assert_equal 1, topics.size 
     217    assert_equal "Mary", topics[0].author_name 
    195218  end 
    196219