Hi all,

I have a primary model with a "before_update" event and a secondary model 
with a foreign key to the primary model.  When I create a secondary model, 
the primary model's "before_update" event is triggered.  I believe this is 
because the backref is being updated.  Can I prevent this behavior?


class Primary(Model):
    id = Column(Integer)

@event.listens_for(Primary, 'before_update')
def example(m, c, t):
   print("I was triggered by a mapper update!")

class Secondary(Model):
    primary_id = Column(ForeignKey)
    primary = orm.relationship('Primary', backref='secondaries')


s = Secondary(primary_id=1)
session.add(s)
session.commit()

>>> I was triggered by a mapper update!

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to