title: Trigger in sqlachemy
body: <p>I have two tables related via a foreign key, here they are using Declarative Mapping</p>
  
  <pre><code>class Task(DeclarativeBase):
      __tablename__ = 'task'
      id = Column(Integer, primary_key=True)
      state = Column(Integer, default=0)
      obs_id = Column(Integer, ForeignKey('obs.id'), nullable=False)
  
  class Obs(DeclarativeBase):
      __tablename__ = 'obs'
      id = Column(Integer, primary_key=True)
      state = Column(Integer, default=0)
  </code></pre>
  
  <p>So, I would like to update the related task.state when obs.state is changed to value 2. Currently I'm doing it by hand (using a relationship called task)</p>
  
  <pre><code>obs.state = 2
  obs.task.state = 2
  </code></pre>
  
  <p>But I would prefer doing it using a trigger. I have checked that this works in sqlite</p>
  
  <pre><code>CREATE TRIGGER update_task_state UPDATE OF state ON obs
    BEGIN
      UPDATE task SET state = 2 WHERE (obs_id = old.id) and (new.state = 2);
    END;
  </code></pre>
  
  <p>But I can't find how to express this in sqlalchemy. I have read <a href="http://www.sqlalchemy.org/docs/core/schema.html#column-insert-update-defaults" rel="noreferrer" title="insert-update-defaults">insert update defaults</a> several times, but can't find the way. I don't know if it's even possible.</p>