Repository navigation
fix: order lane cells by the board query's order like columns - #230
Merged
Merged
Conversation
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.
A board whose query already carries an
orderBy()was sorted with lanes off and lost that sort as soon as lanes were switched on: lane cells always fell back to manual position. Lane cells now order their cards by the board query's own orders first, then by position and key, exactly as columns do.What changed
HasBoardGroupings::getLaneRecordsQuery()reads the orders (and theirorderbindings) from the filtered, lane-scoped query before it clears them. The protected helpercompileBoardOrders()compiles them with the connection grammar. They go first in therow_number() over (partition by <column> order by ...)window, ahead of position and key. The per-cell limit and the finalflowforge_cell_rowordering come from that ranking, so the top N of a cell is now the top N by the board order.flowforge_cell_total,laneHasCards()and the count paths are untouched.How each stored order shape is compiled:
table.column) is compiled as is.order bysees only input columns, so a bare name shared with a joined table (for examplelatest()with a joinedcreated_at) would be ambiguous there while it works in a flat query.ORDER BYresolves a bare name to the output alias first, so compiling the table column would sort differently from the flat board.Expressionorder or a subquery order is guarded byselectAliases()andmentionsAlias(). Every select item is collected: each top-level comma-separated part of a raw select, quoted and unquoted aliases, andselectSubandwithCountaliases. The order SQL is then checked, outside string literals, for an alias as a whole token or as a quoted identifier. A token followed by(is a function call and does not count.orderbucket to the end of theselectbucket, where the window expression sits, so select, from, where and order bindings stay aligned. The orders are removed from the inner query as before, so nothing is bound twice.Why this way
The window function applies the per-cell limit, so the order has to live in it. Ordering only the outer query would keep the top N by position and merely re-sort them. Global scope orders are deliberately not read: they are added by
applyScopes()after the orders are captured, and an existing test pins that they never reach lane queries. Output aliases cannot be referenced inside a window on Postgres, which is why a bare non-column name falls back instead of being compiled.Behaviour to know about
orderBynow orders lane cells too. Hosts that relied on lanes ignoring a query order will see cards reorder.withCountcolumn) or that a selected alias shadows, aninOrderOforder, and a raw or expression order that uses a selected alias by name. A raw order that only calls a function with an alias's name, such ascount(*), is honoured.distinctrule: the window then sits on a wrapper subquery, so an order is honoured only when it is a plain column of the model's own table that the select list includes (table.*,*, or the column by name). Any other order falls back to position order.meta->rank, falls back too. To get it into lanes, qualify the column or useorderByRaw.aswhen a raw order refers to them. An alias with noasand no closing parenthesis (selectRaw('tasks.estimated_hours hrs')) is not detected, so a raw order on it reaches the window and Postgres rejects it.Tests
All in
tests/Modern/Feature/GroupingTest.php, with order shapes added to theTestGroupedBoardandTestCastGroupedBoardfixtures. Tests marked pgsql run in CI's PostgreSQL job.withCountquery (pgsql).orderByRawwith a binding, a subquery order with a binding, and afromSubbase query whose subquery select carries a binding, each beside select, where and order bindings (pgsql). A mutation that put the order bindings first in the select bucket fails the first two.lower(title) as title) falls back to position order (pgsql).select('tasks.*')board withlatest(), and a bareorderBy('id')shared with a joined table (pgsql).count(*)whilecountis an alias is honoured, and a raw order with a string literal equal to an alias is honoured (pgsql).distinct: an honoured own-table column, and the fallbacks for a raw order and for an unselected joined column, seeded with distinct values so honouring would visibly reorder (SQLite only: the fixture selects a json column underdistinct, which Postgres rejects regardless of this change).Checked
At
8246dafcf: the full suite on SQLite, 685 passed.pest --group=pgsqlagainst a scratch PostgreSQL database, 86 passed.pint --testpasses. CI on this head: all jobs pass (PHP 8.3 and 8.4 on Laravel 12 and 13, PostgreSQL, Browser chromium and webkit, code styling, docs build, without panels). PHPStan reports the same 10 errors as a clean4.xcheckout, none inHasBoardGroupings.php, baseline untouched. The new alias and ambiguity tests failed on the earlier heads (ade1d83f5,99b6dec1c) before their fixes.Not checked
unionqueries (unionOrders) are not read.asis detected only when it follows a closing parenthesis (see Behaviour to know about).distinct, run it against a fixture without a json column.