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

Changeset 7076

Show
Ignore:
Timestamp:
06/21/07 20:50:53 (1 year ago)
Author:
bitsweat
Message:

Merge [7075] to stable: save associated records only if the association is already loaded. References #8713.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1-2-stable/activerecord/CHANGELOG

    r7012 r7076  
    11*SVN* 
     2 
     3* Save associated records only if the association is already loaded.  #8713 [blaine] 
    24 
    35* Changing the :default Date format doesn't break date quoting.  #6312 [bshand, Elias] 
  • branches/1-2-stable/activerecord/lib/active_record/associations.rb

    r6805 r7076  
    994994          after_callback = <<-end_eval 
    995995            association = instance_variable_get("@#{association_name}") 
    996              
    997             if association.respond_to?(:loaded?) 
     996 
     997            if association.respond_to?(:loaded?) && association.loaded? 
    998998              if @new_record_before_save 
    999999                records_to_save = association 
     
    10051005            end 
    10061006          end_eval 
    1007                  
     1007 
    10081008          # Doesn't use after_save as that would save associations added in after_create/after_update twice 
    10091009          after_create(after_callback) 
  • branches/1-2-stable/activerecord/test/associations_test.rb

    r6805 r7076  
    6868 
    6969class AssociationProxyTest < Test::Unit::TestCase 
    70   fixtures :authors, :posts 
    71    
     70  fixtures :authors, :posts, :developers, :projects, :developers_projects 
     71 
    7272  def test_proxy_accessors 
    7373    welcome = posts(:welcome) 
     
    8787    david.posts_with_extension.first   # force load target 
    8888    assert_equal  david.posts_with_extension, david.posts_with_extension.testing_proxy_target 
     89  end 
     90 
     91  def test_save_on_parent_does_not_load_target 
     92    david = developers(:david) 
     93 
     94    assert !david.projects.loaded? 
     95    david.update_attribute(:created_at, Time.now) 
     96    assert !david.projects.loaded? 
    8997  end 
    9098end