On Apr 1, 2013, at 2:10 PM, Michael Merickel <[email protected]> wrote:
> I ran into a situation the other day where I would create a new object but > copy over some properties from an earlier version of the object. To do this, > I first created the new object, then I queried the database for the latest > copy of the object, copied properties to the new object, then added the new > object to the session and committed. I was very surprised to discover that > the new object (which was not added to the session) was returned from the > database query as the "latest" object. > > bar = session.query(Bar).first() > > new_foo = Foo() > new_foo.bar = bar # apparently causes new_obj to be added to the session this behavior is known as "cascade", and is described in detail here: http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#cascades . It can be fully customized, but it seems like you are at least expecting basic forwards-direction "save-update" cascade to occur. Cascade also takes place during backref events. The specific behavior regarding bi-directional cascades due to backrefs, as well as controlling their behavior using the "cascade_backrefs" flag, is here: http://docs.sqlalchemy.org/en/rel_0_8/orm/session.html#controlling-cascade-on-backrefs -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
