code: def setup_listener(mapper, class_):
      name = class_.__name__
      discriminator = name.lower()
      class_.addresses = relationship(
          Address,
          primaryjoin=and_(
              class_.id == foreign(remote(Address.parent_id)),
              Address.discriminator == discriminator,
          ),
          backref=backref(
              "parent_%s" % discriminator,
              primaryjoin=remote(class_.id)
              == foreign(Address.parent_id),
          ),
      )
  
      @event.listens_for(class_.addresses, "append")
      def append_address(target, value, initiator):
          value.discriminator = discriminator
  
imports: from sqlalchemy import and_
  from sqlalchemy import Column
  from sqlalchemy import create_engine
  from sqlalchemy import event
  from sqlalchemy import Integer
  from sqlalchemy import String
  from sqlalchemy.ext.declarative import as_declarative
  from sqlalchemy.ext.declarative import declared_attr
  from sqlalchemy.orm import backref
  from sqlalchemy.orm import foreign
  from sqlalchemy.orm import relationship
  from sqlalchemy.orm import remote
  from sqlalchemy.orm import Session
label_desc: Use image node_id 1 for calling a global function with example usage: setup_listener(mapper, class_) without return types