Cyril Scetbon <[email protected]> wrote:
> I've already tried. But when I try to define a listener it says the user > attribute does not exist on Address which is true as it's not defined. I > suppose there is a time when it's defined (hen the relationship is actually > auto-generated) and maybe it's just the location of the event which is not > the right one. two choices: 1. call configure_mappers() so that the backref resolves itself to the other side. 2. use two distinct relationship() objects with back_populates instead. See docs.sqlalchemy.org/en/rel_0_9/orm/backref.html. > Le mardi 24 mars 2015 14:23:00 UTC+1, Michael Bayer a écrit : > the “user” backref here is a relationship() like any other, just specify > Address.user as the target of the event. > > Cyril Scetbon <[email protected]> wrote: > > > Hi, > > > > Is there a way to add an event listener on a backref ? > > > > I have something like : > > > > class User(Base): > > > > > > __tablename__ = 'user' > > > > > > id = Column(Integer, primary_key=True) > > > > > > name = Column(String) > > > > > > > > addresses = relationship("Address", backref="user") > > > > > > > > class Address(Base): > > > > > > __tablename__ = 'address' > > > > > > id = Column(Integer, primary_key=True) > > > > > > email = Column(String) > > > > > > user_id = Column(Integer, ForeignKey('user.id')) > > > > > > I'd like to do add an action when a dev set the attribute Address.user. > > > > -- > > 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 [email protected]. > > To post to this group, send email to [email protected]. > > 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
