Fix ArgumentError sorting unnamed foreign keys when one is composite - #378
Open
6temes wants to merge 1 commit into
Open
Fix ArgumentError sorting unnamed foreign keys when one is composite#3786temes wants to merge 1 commit into
6temes wants to merge 1 commit into
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.
Fixes #377
Problem
ForeignKeyComponentBuilder#formatted_namefalls back to the rawforeign_key.columnwhen 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, andAnnotationBuilder#build'ssort_by { |fk| [fk.formatted_name, fk.stringified_columns] }raisesArgumentError: comparison of Array with Array failed. In a Rails app this makes everydb:migrate/db:rollbackexit non-zero after the migration completes, since the rake hook runs afterwards.Fix
Use the existing
stringified_columnsas 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 styleref_infoalready uses. This also makes themax_sizepadding measure the rendered width instead ofArray#size.Verification
ArgumentErrorwithout the fix and passes with it.mainin my environment (the same 26 pre-existing failures on both, unrelated to this change).