This project is archived and is in readonly mode.
Assigning nested attributes fails for new object when ID is specified
-
David Trasbo
- Assigned user set to Ryan Bigg
Tyler,
In this case you should use
arm_ids:Person.new(:arm_ids => [1, 2, 3])This ticket can be marked as invalid.
-
Ryan Bigg
- State changed from new to invalid
-
Dave Myron
- Importance changed from to Low
I'd like to reopen discussion on this. Consider a three-level nested attribute setup: Something like Subscription -> User -> Credit Card (each accepting nested attributes of the parent) and in the Subscription form you have the Subscription, User and Credit Card fields.
If the User exists but doesn't have a Credit Card yet, then this error is thrown when trying to create a Subscription with an existing user and trying to provide Credit Card details. Imagine the Subscription form having a dropdown of existing users which would set
subscription[user_attributes][id]and then specifyingsubscription[user_attributes][credit_card_attributes]values.The resulting params would look something like
{:subscription => {:user_attributes => {:id => 1, :credit_card_attributes => { ... }}}I'd expect that work (as did the original reporter).
Can you suggest an existing way to accomplish this? (You wouldn't be able to use nested attributes, I'm guessing, and instead have to look for a separate credit_card param and shim it in.)
-
Dave Myron
In
assign_nested_attributes_for_one_to_one_associationmaybe it ought to look at thepersisted?state and, if not persisted, reflect on the association and use the itsfindwith theidgiven in the attributes.I'm curious if CVE-2010-3933 (Rails v3.0.1) is related to this.
-
Dave Myron
Hmm... looks like my suggestion above is exactly what was removed in Rails v3.0.1 because of CVE-2010-3933. That's a bummer.