I want to query specific objects of Reference. But I want that list ordered by its child objects (you could say relation): Reference._periodical._name and Reference._author._lastname' (means the __first__ author, which are orded byReferenceAuthor.Index`).
Can not see how to do this. This is the query but without the ordering in it.
return self.session.query(Reference) \
.filter_by(_mark = False) \
#.order_by(Reference._periodical) \
#.order_by(Reference._author._lastname) \
.all()
This is the model itself
ReferenceAuthor = sa.Table('ReferenceAuthor', _Base.metadata,
sa.Column('ReferenceID', sa.Integer, sa.ForeignKey('Reference.ID'), primary_key=True),
sa.Column('PersonID', sa.Integer, sa.ForeignKey('Person.ID'), primary_key=True),
sa.Column('Index', sa.Integer)
)
class Reference(_Base):
__tablename__ = 'Reference'
_id = sa.Column('ID', sa.Integer, primary_key=True)
_mark = sa.Column('HasLabel', sa.Boolean)
# Autor
_authors = sao.relationship('Person', secondary=ReferenceAuthor,
order_by=ReferenceAuthor.c.Index)
# Journal
_periodical_fk = sa.Column('PeriodicalID',
sa.Integer,
sa.ForeignKey('Periodical.ID'))
_periodical = sao.relationship('Periodical')
class Periodical(_Base):
__tablename__ = 'Periodical'
_id = sa.Column('ID', sa.Integer, primary_key=True)
_name = sa.Column('Name', sa.String)
class Person(_Base):
__tablename__ = 'Person'
_id = sa.Column('ID', sa.Integer, primary_key=True)
_lastname = sa.Column('LastName', sa.String)