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

Changeset 3332

Show
Ignore:
Timestamp:
12/21/05 16:56:32 (4 years ago)
Author:
csshsh
Message:

Fixed that saving a model with multiple habtm associations would only save the first one.

Files:

Legend:

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

    r3296 r3332  
    1 *  
     1*SVN* 
     2 
     3* Fixed that saving a model with multiple habtm associations would only save the first one.  #3244 [yanowitz-rubyonrails@quantumfoam.org, Florian Weber] 
     4 
     5 
    26*1.13.2* (December 13th, 2005) 
    37 
  • branches/stable/activerecord/lib/active_record/associations.rb

    r3241 r3332  
    784784          method_name = "validate_associated_records_for_#{association_name}".to_sym 
    785785          define_method(method_name) do 
    786             @new_record_before_save = new_record? 
    787786            association = instance_variable_get("@#{association_name}") 
    788787            if association.respond_to?(:loaded?) 
     
    798797 
    799798          validate method_name 
    800  
     799          before_save("@new_record_before_save = new_record?; true") 
     800           
    801801          after_callback = <<-end_eval 
    802802            association = instance_variable_get("@#{association_name}") 
     
    810810              association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id 
    811811            end 
    812  
    813             @new_record_before_save = false 
    814             true 
    815812          end_eval 
    816813 
  • branches/stable/activerecord/test/associations_test.rb

    r3255 r3332  
    11741174  end 
    11751175 
     1176  def test_habtm_saving_multiple_relationships 
     1177    new_project = Project.new("name" => "Grimetime") 
     1178    amount_of_developers = 4 
     1179    developers = (0..amount_of_developers).collect {|i| Developer.create(:name => "JME #{i}") } 
     1180   
     1181    new_project.developer_ids = [developers[0].id, developers[1].id] 
     1182    new_project.developers_with_callback_ids = [developers[2].id, developers[3].id] 
     1183    assert new_project.save 
     1184     
     1185    new_project.reload 
     1186    assert_equal amount_of_developers, new_project.developers.size 
     1187    amount_of_developers.times do |i| 
     1188      assert_equal developers[i].name, new_project.developers[i].name 
     1189    end 
     1190  end 
     1191 
    11761192  def test_build 
    11771193    devel = Developer.find(1)