Skip to content

Instantly share code, notes, and snippets.

@jfirebaugh
Created April 2, 2010 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfirebaugh/352595 to your computer and use it in GitHub Desktop.
Save jfirebaugh/352595 to your computer and use it in GitHub Desktop.
diff --git a/lib/sequel/plugins/nested_attributes.rb b/lib/sequel/plugins/nested_attributes.rb
index d04176f..b0b3107 100644
--- a/lib/sequel/plugins/nested_attributes.rb
+++ b/lib/sequel/plugins/nested_attributes.rb
@@ -91,6 +91,7 @@ module Sequel
send(reflection[:name]) << obj
after_save_hook{send(reflection.add_method, obj)}
else
+ associations[reflection[:name]] = obj
# Don't need to validate the object twice if :validate association option is not false
# and don't want to validate it at all if it is false.
before_save_hook{send(reflection.setter_method, obj.save(:validate=>false))}
diff --git a/spec/extensions/nested_attributes_spec.rb b/spec/extensions/nested_attributes_spec.rb
index cb95e60..aaadf60 100644
--- a/spec/extensions/nested_attributes_spec.rb
+++ b/spec/extensions/nested_attributes_spec.rb
@@ -239,6 +239,8 @@ describe "NestedAttributes plugin" do
proc{a.save}.should raise_error(Sequel::ValidationFailed)
a.errors.full_messages.should == ['artist name cannot be Ar']
@mods.should == []
+ # Should preserve attributes
+ a.artist.name.should == 'Ar'
end
it "should not attempt to validate nested attributes if the :validate=>false association option is used" do
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment