On Jan 10, 2008, at 10:17 AM, Laurent Houdard wrote:
>
> On Jan 10, 4:00 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
>> A statement issued in SessionExtension would fire unconditionally
>> upon
>> any flush(), so thats the trigger there. not sure what you mean by
>> "track" here, if it means you want to know the keywords that were
>> deleted, you'd just issue the above SELECT first, do something with
>> the rows, then the DELETE.
>
> I want to know the keywords that were deleted, but it's more
> complicated... keywords are mapped to Keyword objects with another
> relation and cascading rules. I would like those cascading rules to
> apply, and know it in SessionExtension.
how about, go into sessionextension.after_flush(), make a new session
local to the operation, issue a Query with the Select for all orphan
keywords, delete them all and flush that sub-session, then expunge()
those keywords from the parent session sent to after_flush, like this:
class MyExt(SessionExtension):
def after_flush(self, session, flush_context):
sess = create_session(bind=session.connection())
keywords = sess.query(Keyword).filter(~exists([1],
keyword_items.c.keyword_id==Keyword.id)).all()
for k in keywords:
sess.delete(k)
sess.flush()
for k in keywords:
if k in session:
session.expunge(k)
Session = sessionmaker(extension=MyExt())
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---