My mind keeps going back to events but of course there's the limitation to 
modifying Session state while handling various events. (
http://docs.sqlalchemy.org/en/rel_0_7/orm/events.html#sqlalchemy.orm.events.MapperEvents.after_update
)

But what about using the SQL Expression API?

*Relevant code snippet:*

class MyModel(Base):
    __tablename__ = "MyTable"
    priid = Column(Integer(), primary_key=True)
    secid = Column(Integer())
 
 
@listens_for(MyModel, 'after_insert')
def mymodel_after_insert(mapper, connection, target):
    mytable = MyModel.__table__
    priid = target.priid
    statement = (mytable.update()
                            .where(mytable.c.priid == priid)
                            .values(secid=priid))
    connection.execute(statement)


Full code for reference:  
http://paste.pound-python.org/show/WVciGm4jCxgvz84jKrZy/
SQLA echo: http://paste.pound-python.org/show/hSyCGisr0X5eupVdyk3f/

The echo looks sane, though I can't be sure how the SQLAchemy internals are 
affected by this.

Thank you for your input, Michael.

Nick

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

Reply via email to