title: How to get a field from from last row of an change log table in SQLAlchemy
body: <p>I have the follow example. When calling Order.next I would expect to return a single order in the with the status <code>NEW</code>. However I am getting Orders in other <code>OrderStatus</code>.</p>
  
  <p>If it matters this is using SQLite backend.</p>
  
  <pre class="lang-py prettyprint-override"><code>class OrderStatus(enum.Enum):
      NEW = 0
      MAKING = 1
      MADE = 2
      COLLECTED = 3
  
  
  class Order(Base):
      __tablename__ = 'orders'
      id = Column(Integer, primary_key=True)
      updates = relationship("OrderUpdate", order_by = "OrderUpdate.position", collection_class=ordering_list('position'))
  
      @hybrid_method
      def next(self):
          order = Order.query                              \
              .filter(Order.status in [OrderStatus.NEW])   \
              .order_by(Order.id)                          \
              .first()
          return order
  
      @hybrid_property
      def status(self):
          update = OrderUpdate                        \
              .query.filter_by(order_id = self.id)    \
              .order_by(OrderUpdate.id.desc())        \
              .first()
          if update is None:
              return None
          return update.status
  
  
  class OrderUpdate(Base):
      __tablename__ = 'order_updates'
      id = Column(Integer, primary_key=True)
      position = Column(Integer)
      status = Column('status', Enum(OrderStatus))
      comment = Column(String)
      order_id = Column(Integer, ForeignKey("orders.id"))
      order = relationship("Order", back_populates="updates")
  </code></pre>