When you adjust the query to join with another table, then use param based sorting, SQLAlchemy will sometimes assume the wrong entity if they both have that field name on it.
class DocumentListResource(ListBase):
db_cls = ents.Document
def base_query(self, req, **kwargs):
portfolio = req.context["portfolio"]
query = self.session.query(self.db_cls).select_from(self.db_cls).join(ents.Portfolio)
return query
// HTTP request: /api/portfolio/document?sort_by=-created_ts
// Resulting query: SELECT * FROM documents JOIN portfolios ON portfolios.id = documents.portfolio_id ORDER BY portfolios.created_ts DESC