Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a false positive for unindexed_foreign_keys when having foreign key on a primary key column #157

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def detect
next unless named_like_foreign_key?(column) || foreign_key?(table, column)
next if indexed?(table, column)
next if indexed_as_polymorphic?(table, column)
next if connection.primary_key(table) == column.name

type_column_name = type_column_name(column)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def test_indexed_foreign_key_is_not_reported
refute_problems
end

def test_foreign_key_is_a_primary_key_not_reported
Context.create_table(:parents)
Context.create_table(:children, primary_key: :parent_id)
ActiveRecord::Base.connection.add_foreign_key(:children, :parents)

refute_problems
end

def test_config_ignore_tables
skip("MySQL always indexes foreign keys") if mysql?

Expand Down