Repository navigation
Don't let a column default decide where a new record goes - #69
Merged
Merged
Conversation
A position column with a default (e.g. `default: 0`) made every new record that wasn't given a position use the default as its requested position. 0 is clamped to 1, so new records went to the top of the list instead of the end, contrary to the README. Several issues trace back to a default on the column (#30, #49, #61). The column writer already forces `position_changed?` for any assignment, so on create an unchanged position means nothing was requested. Treat it as nil. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
If the position column has a default (e.g.
null: false, default: 0), a new record created without a position uses the default as its requested position.0is clamped to1, so every new record goes to the top of the list: three records created in order end up as[3, 2, 1]. The README says records created without a position go to the end.The advice in #30, #49 and #61 has been "don't put a default on the column", and that's still good advice. But people keep doing it (often carried over from acts_as_list migrations), the README doesn't say so anywhere, and the result is silent misordering rather than an error.
Fix
The column writer already forces
position_changed?for any assignment (even of the same value), so on create an unchanged position can only mean nothing was requested. Treat it as nil:An explicit
position: 0(equal to the default) is still respected; there's a test for that.Tests
New
default_position_itemsfixture withdefault: 0. The ordering test fails onmainwith[3, 2, 1].Changelog: A default on the position column no longer places new records at the start of the list.
🤖 Generated with Claude Code