Skip to content

Don't let a column default decide where a new record goes - #69

Merged
brendon merged 4 commits into
mainfrom
fix/ignore-column-defaults
Oct 21, 2026
Merged

brendon merged 4 commits into
mainfrom
fix/ignore-column-defaults

Conversation

@brendon

@brendon brendon commented Oct 16, 2026

Copy link
Copy Markdown
Owner

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. 0 is clamped to 1, 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:

clear_position unless position_changed?

An explicit position: 0 (equal to the default) is still respected; there's a test for that.

Tests

New default_position_items fixture with default: 0. The ordering test fails on main with [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

brendon and others added 4 commits October 16, 2026 12:07
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>
@brendon
brendon merged commit b6ee153 into main Oct 21, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant