What's strange is that I can't recreate the problem on more simple
stage.  Every time I refresh() on the parent object, the list objects
remain the same.  In other words, *sometimes* it behaves as I hope it
to (by apparently refreshing the list's objects) and *sometimes* if
throws them out and creates new ones.  The mystery to me is what
determines when it will create new instances vs. refreshing the
existing ones?



On Mar 4, 3:24 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote:
> Kent wrote:
> > If I use session.refresh(obj) to re-load an obj that has a one-to-many
> > relational property, the objects in the list are *replaced* instead of
> > *refreshed* if they already exist.
>
> > Suppose department has a list of employees:
>
> > suppose dept.employees = [ emp1, emp2 ]
>
> > session.refresh(dept)
>
> > the dept."employees" list's elements are replaced with new objects
> > instead of reusing those that existed and refreshing them.
>
> > Is it possible to have those same objects re-used and simply refreshed
> > instead of replaced?
>
> you can only turn off "refresh-expire" cascade, which will prohibit the
> operation from traveling into the child objects.  the collection is still
> refreshed for obvious reasons, its one of the attributes on your mapped
> object.
>
> To achieve your specified behavior, use session.refresh() given as its
> second argument the set of attribute names which are safe to be reloaded
> completely (in this case the scalars).   Then for each uselist attribute,
> iterate the collection of each and call the desired version of
> session.refresh() for those.
>
> This is an easy refresh() function to create in a generalized way by
> inspecting the class-level attributes of the incoming object.
>
>
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "sqlalchemy" group.
> > To post to this group, send email to sqlalch...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/sqlalchemy?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to