Validates associated uniqueness for nested attributes #8308
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
As pointed out in #1572 and #4568, there is no uniqueness validation for nested attributes. It does check against the db for duplicate records but doesn't check the collection being passed in. This checks for that only when there is a uniqueness validation defined in the associated model.
It is a basic uniqueness validation by combining the attributes defined in the uniqueness validator. I've chosen to only pull the necessary attributes to generate the "key" instead of all attributes https://github.com/jeyb/rails/commit/1f618ff24e284e6aad15da43952ed3d45cc1d621 in case there are timestamps that or other user generated content that throws off the uniqueness check.
Let me know what you guys think.