This repository has been archived by the owner on Dec 12, 2021. It is now read-only.
Allow nested associations with same name (fixes #237) #238
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.
Suggestion cannot be applied right now. Please check back later.
This fixes #237 by using more specific regular expressions for nested associations.
Example
Think of this model: A has_many B. B has_many B.
Right now if you are in the form of A and click the add link, the blueprint will be loaded and every occurence of the regexp
/(_b_attributes)_.+?_/g
will be replaced with$1_0_
and every occurence of/(\[b_attributes\])\[.+?\]/g
will be replaced with$1[0]
. Thats okay for the first nesting level (as this contains simple names asa[b_attributes][new_b][_destroy]
). However, in the second level (e.g. name =a[b_attributes][new_b][b_attributes][new_b][_destroy]
) this will not work anymore, as the first replace will catch both occurences of both associations since they have the same name.My patch is to make the regexps more specific by prepending the full path of the parent associations.
This pull request does not entirely fix support for recursive associations, but it allows users to fix it on their own, see #237 on how to. Of course, it would be awesome if even that wouldn't be necessary some day.