This feels more like a question to ask the core list, forgive me if I trespass.
I've been trying to help one of my cow orkers get through a sticky
problem. He's got a fairly complex nested form to update a model and
its children. He's started adding some validations, and we've
encountered a number of issues:
First he had a validation on one of the child models which needed to
be conditional on an attribute in the parent model. We realized that
on a save, the child was fetching the parent from the database, and so
was seeing the old value in the parent.
This led me to the discovery of the :inverse_of option on :belongs_to
and :has_xxx associations. Adding this option to both ends of the
associations in question fixed the problem of the validation not
triggering, and that's when we noticed a second problem.
Lets say we enter a value for an attribute of one of the child models,
and validation of the parent fails. Using the normal pattern of
rendering the edit action when the update fails doesn't show the 'new'
values entered for the attribute(s) of the child(ren). Part of the
problem is because active record now has this normally nice feature of
deferring sequel queries until the data is needed, which, if you're
not careful, causes rendering of the edit view to refetch the data.
It feels like we are working too hard and changing too much controller
code to fix this, and not succeeding all that well to boot.
It also occurs to me that the IdentityMap stuff now in Edge might be
the solution or part of the solution to this problem. As I understand
it this will prevent multiple instantiations of the same AR object in
a given thread. What we really want is for the in-memory object graph
to be preserved and keep the attributes from being overwritten by
queries. I haven't dug through the InstanceMap code enough yet to see
if that is the case.
I'm loath to move to edge just to try this.
Any advice from the core-savvy guys.