Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed that autosave should validate associations even if master is in…
…valid [#1930 status:committed]
- Loading branch information
Showing
9 changed files
with
629 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5cda000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: This commit does quite some more than the commit message explains.
I basically moved all code related to auto validating and saving associations that existed prior to AutosaveAssociation into AutosaveAssociation.
It should not change any existing API.
5cda000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see one problem here. For models with many (really many) associations this code would generate tons of dummy validation methods that would call those validate_collection_association/validate_single_association. In our project with hundreds of highly-relational models (some models have 50+ associations) this causes the code to work significantly slower (tests execution time x 1.5).
I've created a patch here, that would simply skip validation methods generation for associations, that weren't specifically requested to be validating ones (:validate => true) and are not :has_many ones. The only problem I see is that this patch would break David's tests that assume validation to be done for every association (which is not correct according to official API docs where only has_many association is auto-validated by default).
5cda000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, to clarify my previous comment: this patch changes the API (it causes all associations to be auto-validating even though docs say only has_many should be) and it hurts performance (in some cases pretty noticeably).
I'm wondering if I should open a ticket and attach my patch with fixed code and tests (not sure what is the official procedure in such a cases).
5cda000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case I accidentally changed the behavior I would love a ticket with the explanation and your patch! The branch I'm pulling in patches on is http://github.com/alloy/rails/commits/2-3-nested_attributes_and_autosave, so you might want to make sure your patch will work with that branch and I will afterwards rebase it to the latest 2.3 revision. Thanks!
5cda000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://rails.lighthouseapp.com/projects/8994/tickets/3161-patch-autosaveassociation-generates-unneeded-validations - here is the patch with my comments and tests