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