This is a full example that shows how mixin classes can be implemented for use with SQLALchemy in a way that also automatically apply event listeners to appropriate subclasses of a given mixin class. The use case started with this question on StackOverflow which asked about how the before_delete
mapper event can be used, which lead down the path of exploration that lead to this more generic skeleton on how this might be achieved in a more generic manner.
The following is an example run of the associated Python code:
INFO:sqlalchemy.engine.Engine:SELECT entity.id AS entity_id, entity.field_a AS entity_field_a, entity.field_b AS entity_field_b, entity.created_at AS entity_created_at, entity.deleted_at AS entity_deleted_at
FROM entity
INFO:sqlalchemy.engine.Engine:[generated in 0.00009s] ()