Skip to content

Fix ArgumentError sorting unnamed foreign keys when one is composite - #378

Open
6temes wants to merge 1 commit into
drwl:mainfrom
6temes:fix/unnamed-composite-foreign-key-sort
Open

Fix ArgumentError sorting unnamed foreign keys when one is composite#378
6temes wants to merge 1 commit into
drwl:mainfrom
6temes:fix/unnamed-composite-foreign-key-sort

Conversation

@6temes

@6temes 6temes commented Aug 10, 2026

Copy link
Copy Markdown

Fixes #377

Problem

ForeignKeyComponentBuilder#formatted_name falls back to the raw foreign_key.column when a foreign key has no name. On adapters that report unnamed foreign keys (SQLite reports all of them that way), a composite foreign key yields an Array while ordinary ones yield a String, and AnnotationBuilder#build's sort_by { |fk| [fk.formatted_name, fk.stringified_columns] } raises ArgumentError: comparison of Array with Array failed. In a Rails app this makes every db:migrate/db:rollback exit non-zero after the migration completes, since the rake hook runs afterwards.

Fix

Use the existing stringified_columns as the no-name fallback, so the sort key and the rendered name are always Strings. For a composite key that renders as [delivery_on, menu_id], matching the style ref_info already uses. This also makes the max_size padding measure the rendered width instead of Array#size.

Verification

  • New spec (unnamed simple + unnamed composite key on one model) reproduces the exact ArgumentError without the fix and passes with it.
  • Full suite failure count is unchanged versus main in my environment (the same 26 pre-existing failures on both, unrelated to this change).

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.

Foreign-key annotation crashes with ArgumentError when unnamed FKs mix with a composite FK

1 participant