database_consistency
Advanced tools
@@ -27,4 +27,4 @@ # frozen_string_literal: true | ||
| def foreign_key_exists? # rubocop:disable Metrics/AbcSize | ||
| model.connection.foreign_keys(model.table_name).any? do |foreign_key| | ||
| def foreign_key # rubocop:disable Metrics/AbcSize | ||
| model.connection.foreign_keys(model.table_name).find do |foreign_key| | ||
| (Helper.extract_columns(association.foreign_key) - Array.wrap(foreign_key.column)).empty? && | ||
@@ -31,0 +31,0 @@ foreign_key.to_table == association.klass.table_name |
@@ -46,3 +46,3 @@ # frozen_string_literal: true | ||
| def check | ||
| if foreign_key_exists? | ||
| if foreign_key | ||
| report_template(:ok) | ||
@@ -49,0 +49,0 @@ else |
@@ -18,3 +18,3 @@ # frozen_string_literal: true | ||
| def preconditions | ||
| association.belongs_to? && foreign_key_exists? | ||
| association.belongs_to? && foreign_key | ||
| end | ||
@@ -38,9 +38,2 @@ | ||
| def foreign_key | ||
| association.klass | ||
| .connection | ||
| .foreign_keys(model.table_name) | ||
| .find { |fk| fk.column == association.foreign_key.to_s } | ||
| end | ||
| def cascade? | ||
@@ -47,0 +40,0 @@ %i[cascade nullify].include? foreign_key.options[:on_delete] |
| # frozen_string_literal: true | ||
| module DatabaseConsistency | ||
| VERSION = '2.1.2' | ||
| VERSION = '2.1.3' | ||
| end |