Skip to content

mapper events should accept a non-mapped class for which mapped subclasses get the event #2585

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

i.e.

import sqlalchemy as sa
from datetime import datetime as dt

class EntityBase(object):

    @declared_attr
    def __tablename__(cls):
        return cls.__name__.lower()

    id = sa.Column(sa.Integer, primary_key=True)
    last_update = sa.Column(sa.DateTime, default=dt.utcnow())

def update_entity(mapper, connection, target):
    target.last_update = dt.utcnow()


Entity = declarative_base(cls=EntityBase)

sa.event.listen(Entity, 'before_insert', update_entity)
sa.event.listen(Entity, 'before_update', update_entity)

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Oct 12, 2012

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

see also #2590.

sqlalchemy-bot

sqlalchemy-bot commented on Oct 12, 2012

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

c30e6d0

sqlalchemy-bot

sqlalchemy-bot commented on Oct 12, 2012

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.8.xx" to "0.8.0"
  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Oct 28, 2012

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

further updates in 8498087

added this to the 0.8.0b1 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          mapper events should accept a non-mapped class for which mapped subclasses get the event · Issue #2585 · sqlalchemy/sqlalchemy