feat(orm): order_by() accepts a correlated-subquery builder#169
Open
tmgbedu wants to merge 2 commits into
Open
feat(orm): order_by() accepts a correlated-subquery builder#169tmgbedu wants to merge 2 commits into
tmgbedu wants to merge 2 commits into
Conversation
order_by() now accepts a QueryBuilder as its column argument and compiles '(subquery) ASC|DESC', mirroring the existing SubSelectExpression handling in where(). Subquery bindings are propagated in the correct position (after WHERE, before nothing that follows ORDER BY). String-based order_by() is unchanged. Covered by grammar-level to_sql()/to_qmark() assertions with binding-order checks across all four dialects (SQLite, MySQL, Postgres, MSSQL), plus a real sqlite-backed suite (categories not in id order) including the full order_by(subquery) -> paginate chain.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
✅ Code Review Verdict: APPROVE (do not merge — approval only, per process)Reviewed for every risk area in the assignment. All pass. (Posted as a comment because GitHub blocks self-approval of one's own PR.) Correctness & binding order
Per-grammar
Regression
Gates reproduced from fastapi_startkit/
Test quality
Minor (non-blocking): double |
Replace raw conn.execute CREATE TABLE / INSERT with the framework's Schema builder and Model.insert(). Same tables and data (categories 1=Zebra, 2=Apple, 3=Mango; posts 1-4), same assertions.
Contributor
Author
✅ Light re-review (force-push / task #911 fixture change) — APPROVE holdsRe-reviewed the single new commit
Do not merge — approval only, per process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up A from splitting #168. Adds correlated-subquery ordering to the async query builder:
order_by()now accepts aQueryBuilderas its column argument and compiles(subquery) ASC|DESC, mirroring the existingSubSelectExpressionhandling inwhere(). Subquery bindings are propagated in the correct position (afterWHERE). String-basedorder_by()is unchanged.Tests
tests/masoniteorm/query/grammars/test_order_by_subquery_grammar.py— grammar-levelto_sql()/to_qmark()+ binding-order assertions across all 4 dialects (SQLite, MySQL, Postgres, MSSQL).tests/masoniteorm/sqlite/builder/test_sqlite_order_by_subquery.py— real sqlite-backed suite (categories deliberately not in id order), including the fullorder_by(subquery) → paginate()chain with paginate-meta assertions.Gates
uv run pytest --ignore=tests/masoniteorm/postgres --cov→ 1807 passed / 7 skipped, coverage 78.87% (≥ fail_under 68).ruff check+ruff format --checkclean.order_by().Relationship to other PRs
Independent of #168 at the code level (the correlated subquery here uses the 2-arg
where_columnthat already exists onmain). #168 adds the operator form ofwhere_column; if you want the operator form in ordering subqueries, merge #168 first. Recommended overall order: #168 → this → follow-up B.