Ticket #8713: always_construct_new_sql_on_save.patch
| File always_construct_new_sql_on_save.patch, 1.9 kB (added by brynary, 1 year ago) |
|---|
-
test/associations_test.rb
old new 14 14 require 'fixtures/comment' 15 15 require 'fixtures/tag' 16 16 require 'fixtures/tagging' 17 require 'fixtures/person' 18 require 'fixtures/reader' 17 19 18 20 class AssociationsTest < Test::Unit::TestCase 19 21 fixtures :accounts, :companies, :developers, :projects, :developers_projects, … … 24 26 Class.new(ActiveRecord::Base).has_many(:wheels, :name => 'wheels') 25 27 end 26 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) 36 end 27 37 28 38 def test_force_reload 29 39 firm = Firm.new("name" => "A New Firm, Inc") -
lib/active_record/associations.rb
old new 1083 1083 [] 1084 1084 end 1085 1085 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 id1089 end1086 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) 1090 1090 end_eval 1091 1091 1092 1092 # Doesn't use after_save as that would save associations added in after_create/after_update twice