Repository navigation
Find the record's own row regardless of default scopes and key changes - #70
Merged
Merged
Conversation
`record_scope` is how Mechanisms reads and moves the record's own row, but it applied the model's default scope and used the in-memory primary key: - A default scope `where` that hides the row (e.g. the archived/soft deleted pattern from #59, with the timestamp in the positioning scope) meant restoring a record raised NoMethodError on nil. - A default scope `select` that omits the scope columns raised MissingAttributeError on any scope change. - Changing part of a composite primary key in the same save as the position meant the row couldn't be found and update_position raised. Use `unscoped` and `id_in_database`; this only affects queries for the record's own row, not the list scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 16, 2026
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.
record_scopeis howMechanismsreads and moves the record's own row (position_was,move_out_of_the_way, and its previous scope and parent). It applied the model's default scope and used the in-memory primary key, which breaks in three ways. All three fail onmain:positioned on: [:list, :archived_at]) alongsidedefault_scope { where(archived_at: nil) }. Archiving works, but restoring raisesNoMethodError: undefined method 'list' for nil, because the default scope filters out the record's own row.selectthat omits the scope columns (like the existingDefaultScopeItemfixture) raisesActiveModel::MissingAttributeError: missing attribute 'list_id'on any scope change.NoMethodError: undefined method '>' for nil.Fix
base_class.unscoped.where(primary_key => [@positioned.id_in_database]), plusid_in_databaseinin_positioning_scope?.This only affects queries about the record's own row. The list scope (
positioning_scope) still applies the default scope. Whether it should is a separate question (multi-tenant default scopes, for example) that this doesn't touch.Changelog: Fix scope changes for records hidden by, or partially selected by, a default scope, and when changing part of a composite primary key.
🤖 Generated with Claude Code