I'm still fairly new at sqlalchemy, and am still occasionally being
surprised by how sometimes-too-clever it is. I ran into one of those
moments today.
I have something that looks like this. (All the tables are reflected.)
class Parent(Model, SimpleLookupTable):
__table__ = Table('parent')
# ....
class Child(Model):
__table__ = Table('child')
parent = relationship("Parent", lazy='joined',
backref=backref('children', lazy='lazy'))
# ....
As part of my program design, I'm sometimes creating a partially-populated
Child() that serves as a 'template' for a child that might be created
later, but isn't at this point.
template = Child(parent = parent)
do_lots_of_stuff()
I was a bit surprised to find that at this point, parent.children already
contains the new Child(). This makes sense when thinking about it under
normal circumstances... but in this particular case, I don't want this to
be part of the collection until it's actually added to the session (which I
can confirm it's not, I've tried both expunging and make_transient().
What's the best way to accomplish this? The documented behavior of
cascade_backrefs=False is almost, but not quite, what I need.
-- Daniel Grace
--
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.