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

Changeset 7942

Show
Ignore:
Timestamp:
10/16/07 07:24:23 (1 year ago)
Author:
bitsweat
Message:

Fix regression where the association would not construct new finder SQL on save causing bogus queries for "WHERE owner_id = NULL" even after owner was saved. Closes #8713.

Files:

Legend:

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

    r7935 r7942  
    11*SVN* 
     2 
     3* Fix regression where the association would not construct new finder SQL on save causing bogus queries for "WHERE owner_id = NULL" even after owner was saved.  #8713 [Bryan Helmkamp] 
    24 
    35* Refactor association create and build so before & after callbacks behave consistently.  #8854 [lifofifo, mortent] 
  • trunk/activerecord/lib/active_record/associations.rb

    r7873 r7942  
    10841084            end 
    10851085 
    1086             if !records_to_save.blank? 
    1087               records_to_save.each { |record| association.send(:insert_record, record) } 
    1088               association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id 
    1089             end 
     1086            records_to_save.each { |record| association.send(:insert_record, record) } unless records_to_save.blank? 
     1087             
     1088            # reconstruct the SQL queries now that we know the owner's id 
     1089            association.send(:construct_sql) if association.respond_to?(:construct_sql) 
    10901090          end_eval 
    10911091 
  • trunk/activerecord/test/associations_test.rb

    r7935 r7942  
    1515require 'fixtures/tag' 
    1616require 'fixtures/tagging' 
     17require 'fixtures/person' 
     18require 'fixtures/reader' 
    1719 
    1820class AssociationsTest < Test::Unit::TestCase 
     
    2426      Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels') 
    2527    end 
     28  end 
     29   
     30  def test_should_construct_new_finder_sql_after_create 
     31    person = Person.new 
     32    assert_equal [], person.readers.find(:all) 
     33    person.save! 
     34    reader = Reader.create! :person => person, :post => Post.new(:title => "foo", :body => "bar") 
     35    assert_equal [reader], person.readers.find(:all) 
    2636  end 
    2737