Skip to content

List base order hook does not respect primary entity in query #6

@matthiaswh

Description

@matthiaswh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions