latest_a = select([func.max(A.a_id).label('a_id'), A.a_remote]).group_by(A.
    a_remote).alias('latest_a')


class B:
    b_id = Column(Integer, primary_key=True)
Correlating a SQLAlchemy relationship with an awkward join