For example:
class Post(Base):
__tablename__ = 'post'
id = Column(Integer, primary_key=True)
text = Column(Unicode)
class Like(Base):
__tablename__ = 'like'
id = Column(Integer, primary_key=True)
post_id = Column(Integer, ForeignKey(Post.id), nullable=False)
class Alert(Base):
__tablename__ = 'alert'
id = Column(Integer, primary_key=True)
like_id = Column(Integer, ForeignKey(Like.id))
Then in SQLAlchemy you can use the following query:
DBSession.query(Alert.id).join(Like).join(Post).filter(Post.id==2).all()