This project is archived and is in readonly mode.
associations do not autosave when a child is modified by creating a "grandchild" thru nested attributes
-
sarah (at ultrasaurus)
We've discovered that if this is done without nested attributes it works fine. The following test passes:
class TestDeepAutosaveAssociationRevised < ActiveRecord::TestCase self.use_transactional_fixtures = false def setup Ship.accepts_nested_attributes_for :parts @ship = Ship.create!(:name => "Bounty") assert_not_nil @ship end def test_that_new_grandchild_will_save_when_child_exists assert_difference "Pirate.count", 1 do assert_difference "ShipPart.count", 1 do assert_no_difference "Ship.count" do @pirate = Pirate.new(:catchphrase => "Arhh!") @pirate.ship = @ship @ship.parts.build(:name => "plank") @pirate.save! end end end end end -
Eloy Duran
- Assigned user set to Eloy Duran
-
sarah (at ultrasaurus)
Eloy -- thanks for taking this on. Now that I've looked at the code a little, I'm quite curious about this (aside from the practical need for a fix). We looked into this last night but couldn't really understand the autosave mechanism. In the second test which passes, how does Rails know that it needs to save the ship when @ship.changed? is false and only its association "parts" has changed?
-
Eloy Duran
- State changed from new to hold
Yes you are quite right, this is the problem. I haven't worked out yet how I'm going to fix this. But after breaking my head over it for a few hours I came to the conclusion that I don't have the right idea atm. I'll be on vacation for the next 3 weeks, so I hope that will clear my thoughts and I can come up with the right one when I'm back.