Python SQLAlchemy onupdate关键字不';连接表中的t触发器
我的班级结构如下:Python SQLAlchemy onupdate关键字不';连接表中的t触发器,python,flask,sqlalchemy,flask-sqlalchemy,flask-restful,Python,Flask,Sqlalchemy,Flask Sqlalchemy,Flask Restful,我的班级结构如下: class A(Model): id = Column(Integer, primary_key=True) text = Column(String(255)) time_updated = Column(DateTime, onupdate=func.now()) type = Column(String(50)) __mapper_args__ = { 'polymorphic_identity': 'a',
class A(Model):
id = Column(Integer, primary_key=True)
text = Column(String(255))
time_updated = Column(DateTime, onupdate=func.now())
type = Column(String(50))
__mapper_args__ = {
'polymorphic_identity': 'a',
'polymorphic_on': type
}
class B(A):
id = Column(Integer, ForeignKey('a.id'), primary_key=True)
more_text = Column(String(255))
__mapper_args__ = {
'polymorphic_identity': 'b',
'inherit_condition': (id == a.id),
}
如果我通过更改more\u text
onupdate
的值来更新B
的实例,则不会触发time\u updated
且不会更改-这是有意义的,因为表B未被触动。但这不是我想要的。如何让SQLAlchemy为实例的所有更改触发onupdate
我尝试在更新之前为事件使用事件侦听器,但这只有在为类B定义事件侦听器时才有效。因为将有更多的类扩展A,所以这不是一个干净的选项。还有更好的办法吗