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

Changeset 3331

Show
Ignore:
Timestamp:
12/21/05 15:50:31 (3 years ago)
Author:
csshsh
Message:

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

Files:

Legend:

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

    r3328 r3331  
    11*SVN* 
     2 
     3* Fixed that saving a model with multiple habtm associations, would only save the first habtm association.  #3244 [yanowitz-rubyonrails@quantumfoam.org, Florian Weber] 
    24 
    35* Fix change_column to work with PostgreSQL 7.x and 8.x.  #3141 [wejn@box.cz, Rick Olson, Scott Barron]  
  • trunk/activerecord/lib/active_record/associations.rb

    r3326 r3331  
    728728          method_name = "validate_associated_records_for_#{association_name}".to_sym 
    729729          define_method(method_name) do 
    730             @new_record_before_save = new_record? 
    731730            association = instance_variable_get("@#{association_name}") 
    732731            if association.respond_to?(:loaded?) 
     
    742741 
    743742          validate method_name 
     743          before_save("@new_record_before_save = new_record?; true") 
    744744 
    745745          after_callback = <<-end_eval 
     
    755755              association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id 
    756756            end 
    757              
    758             @new_record_before_save = false 
    759             true 
    760757          end_eval 
    761758                 
  • trunk/activerecord/test/associations_test.rb

    r3287 r3331  
    11951195  end 
    11961196 
     1197  def test_habtm_saving_multiple_relationships 
     1198    new_project = Project.new("name" => "Grimetime") 
     1199    amount_of_developers = 4 
     1200    developers = (0..amount_of_developers).collect {|i| Developer.create(:name => "JME #{i}") } 
     1201   
     1202    new_project.developer_ids = [developers[0].id, developers[1].id] 
     1203    new_project.developers_with_callback_ids = [developers[2].id, developers[3].id] 
     1204    assert new_project.save 
     1205     
     1206    new_project.reload 
     1207    assert_equal amount_of_developers, new_project.developers.size 
     1208    amount_of_developers.times do |i| 
     1209      assert_equal developers[i].name, new_project.developers[i].name 
     1210    end 
     1211  end 
     1212 
    11971213  def test_build 
    11981214    devel = Developer.find(1)