This project is archived and is in readonly mode.
[AutosaveAssociation] should not validate associated model if marked_for_destruction
-
Dmitry Polushkin
- Tag changed from 2.3-rc1, accepts_nested_attributes_for, validation to 2.3-rc1, accepts_nested_attributes_for, arked_for_destruction, validation
- Title changed from nested attributes to [nested attributes] should not validate associated model marked_for_destruction
-
Eloy Duran
- Title changed from [nested attributes] should not validate associated model marked_for_destruction to [AutosaveAssociation] should not validate associated model if marked_for_destruction
Good catch!
-
DHH
- Milestone cleared.
-
Eloy Duran
Fixed. This patch relies on the patch from #1930 autosave should validate associations even if master is invalid: http://rails.lighthouseapp.com:8...
-
Eloy Duran
And the patch.
-
Eloy Duran
- Assigned user changed from Eloy Duran to Michael Koziarski
-
Dmitry Polushkin
Just applied both patches, works great! Thanks.
-
Repository
(from [e2b925fa68203607fb4f9a9aa457c0435c969f9a]) Don't validate records of an :autosave association if they're marked for destruction. [#2064 [AutosaveAssociation] should not validate associated model if marked_for_dest... status:resolved]
Signed-off-by: David Heinemeier Hansson david@loudthinking.com http://github.com/rails/rails/co...
-
DHH
- State changed from new to resolved
-
Dmitry Polushkin
- Assigned user changed from Michael Koziarski to Eloy Duran
Oh, found another bug related to this topic. When Model marked_for_destruction? and has custom validation, then it's enters to the validation method, but it shouldn't:
class ::Ship validate :validate_name private def validate_name if name && 'mustnt-go-here' == name errors.add(:name, :name_invalid) throw :mustnt_validate_when_marked_for_destruction end end end def test_should_skip_validation_and_destroy_the_associated_model @pirate.ship.update_attribute(:name, 'mustnt-go-here') @pirate.ship.mark_for_destruction assert_nothing_thrown do @pirate.update_attributes({ :ship_attributes => { :id => @ship.id, :_delete => true } }) end endThanks!
-
Eloy Duran
- Tag changed from 2.3-rc1, accepts_nested_attributes_for, arked_for_destruction, validation to 2.3.2, accepts_nested_attributes_for, marked_for_destruction, validation
- State changed from resolved to open
@Dmitry: Sorry that I missed your new comment. Next time please create a new ticket or change the state to open again.
About the problem; have you investigated already where the problem lies? And/or maybe a naive patch or something?
-
Dmitry Polushkin
@Eloy: no, I've tried, but didn't found where is the problem lies.
-
Dmitry Polushkin
The problem is in:
def association_valid?(reflection, association) unless valid = association.valid? if reflection.options[:autosave] unless association.marked_for_destruction?condition unless association.marked_for_destruction? must be before the valid? method invoked.
-
Eloy Duran
That seems obvious yes, good catch again! Are you gonna try to write a patch for it? If not, that's ok then I'll fix it later on.
-
Dmitry Polushkin
Not so good in git, actually. :)
-
Dmitry Polushkin
Patch with tests.
-
Michael Koziarski
- Milestone set to 2.3.4
-
Dmitry Polushkin
New patch is here. Please, if it is possible, push it before 2.3.4 will come out. Thanks.
-
José Valim
+1, applied and it works as expected.
-
Eloy Duran
- State changed from open to verified
I have verified and applied this patch on my branch of 2-3-stable, which Micheal will look at and merge in before 2.3.4.
http://github.com/alloy/rails/commit/dbc56d67b644944dcff09afbcb2f7d...
Thanks!
-
Repository
- State changed from verified to resolved
(from [c52a50ec51f7466411c032d676590be67fd6a956]) Fix autosave association to skip validation if it is marked for destruction. [#2064 [AutosaveAssociation] should not validate associated model if marked_for_dest... state:resolved] Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/c52a50ec51f7466411c032d676590b... -
Repository
(from [845f62f4730fb9ab8847033f9ab7435c40006662]) Fix autosave association to skip validation if it is marked for destruction. [#2064 [AutosaveAssociation] should not validate associated model if marked_for_dest... state:resolved] Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/845f62f4730fb9ab8847033f9ab743...
