Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

groe
Copy link
Contributor

@groe groe commented Feb 11, 2013

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 as a[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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recursive nesting broken in nested_form 0.3.x
1 participant