fabulous, this works great. thanks! now I've got something like this in my code:
def delete_cascade_preview(instance): keys = [rel.key for rel in inspect(instance.__class__).relationships if rel.cascade.delete == True] return {key:getattr(instance, key).all() for key in keys if getattr(instance, key).count() > 0} On Tuesday, July 15, 2014 3:59:21 PM UTC-4, Michael Bayer wrote: > > I’d look at inspect(MyClass).relationships to see where the linkages are > to other classes. Then you can probe those for the features you need - > once you have one, it has a string “key”. you can then see that by just > getattr(someobj, “somekey”). > > > On Jul 15, 2014, at 3:40 PM, Scott Meisburger <smeis...@gmail.com > <javascript:>> wrote: > > I've got an app where through an admin interface, a user can delete > objects in the database. This happens via: > > db.session.delete(obj) > db.session.commit() > > There are cascade rules defined in Python for these objects (using the > ORM). What I want to do is display to the user a list of related objects > that will be deleted along with the parent and have them confirm Yes or No. > At the very least, I'd like to be able to say whether or not there are ANY > related objects which will be deleted. I assume this can be done via some > introspection feature? > > -- > 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 sqlalchemy+...@googlegroups.com <javascript:>. > To post to this group, send email to sqlal...@googlegroups.com > <javascript:>. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. > > > -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.