Skip to content
This repository
Browse code

Fix regression where the association would not construct new finder S…

…QL on save causing bogus queries for "WHERE owner_id = NULL" even after owner was saved. References #8713.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@7940 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 257d8605c9bd8926fbc1c5ea15da5d7abcd1bc78 1 parent a2f0af2
Jeremy Kemper authored October 16, 2007
5  activerecord/CHANGELOG
... ...
@@ -1,3 +1,8 @@
  1
+*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]
  4
+
  5
+
1 6
 *1.15.5* (October 12th, 2007)
2 7
 
3 8
 * Depend on Action Pack 1.4.4
8  activerecord/lib/active_record/associations.rb
@@ -1002,10 +1002,10 @@ def add_multiple_associated_save_callbacks(association_name)
1002 1002
               []
1003 1003
             end
1004 1004
 
1005  
-            if !records_to_save.blank?
1006  
-              records_to_save.each { |record| association.send(:insert_record, record) }
1007  
-              association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
1008  
-            end
  1005
+            records_to_save.each { |record| association.send(:insert_record, record) } unless records_to_save.blank?
  1006
+            
  1007
+            # reconstruct the SQL queries now that we know the owner's id
  1008
+            association.send(:construct_sql) if association.respond_to?(:construct_sql)
1009 1009
           end_eval
1010 1010
 
1011 1011
           # Doesn't use after_save as that would save associations added in after_create/after_update twice
10  activerecord/test/associations_test.rb
@@ -10,6 +10,8 @@
10 10
 require 'fixtures/category'
11 11
 require 'fixtures/post'
12 12
 require 'fixtures/author'
  13
+require 'fixtures/person'
  14
+require 'fixtures/reader'
13 15
 
14 16
 
15 17
 class AssociationsTest < Test::Unit::TestCase
@@ -21,6 +23,14 @@ def test_bad_collection_keys
21 23
       Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels')
22 24
     end
23 25
   end
  26
+  
  27
+  def test_should_construct_new_finder_sql_after_create
  28
+    person = Person.new
  29
+    assert_equal [], person.readers.find(:all)
  30
+    person.save!
  31
+    reader = Reader.create! :person => person, :post => Post.new(:title => "foo", :body => "bar")
  32
+    assert_equal [reader], person.readers.find(:all)
  33
+  end
24 34
 
25 35
   def test_force_reload
26 36
     firm = Firm.new("name" => "A New Firm, Inc")

0 notes on commit 257d860

Please sign in to comment.
Something went wrong with that request. Please try again.