Joseph Palermo
2013-Feb-06 04:29 UTC
inverse_of breaks for unsaved child associations during save of parent
I''m willing to write a patch for this issue: https://github.com/rails/rails/issues/8893 But want to confirm that the new behavior makes sense before I make the effort. Essentially if you have an unsaved parent and child, and the parent''s association to the child has an inverse_of declared on it. When the parent gets saved, it updates the foreign key on the child, and this makes the association stale, breaking the inverse_of connection. It should be pretty easy to fix. Either on the parent''s side by checking to see if the association we''re setting the foreign key on has an inverse_of on it, and if so, declare the inverse association as loaded. Or, probably better than that, on the child, if you think an association is stale because your foreign key to it has changed, double check to see if the id of your existing model matches the new foreign key. Does that sound like a reasonable change to make? Thanks, Joseph Palermo Pivotal Labs -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Seemingly Similar Threads
- accepts_nested_attributes_for, validations, :inverse_of option on associations, and IdentityMap
- Validation dependent on unsaved parent
- inverse_of not supported in Rails 3 for has_many?
- How to use group in nested associations
- how to prevent child.save() when doing parent.save() in associations?