Class: DatabaseConsistency::Checkers::AssociationChecker
- Inherits:
-
BaseChecker
- Object
- BaseChecker
- DatabaseConsistency::Checkers::AssociationChecker
- Defined in:
- lib/database_consistency/checkers/association_checkers/association_checker.rb
Overview
The base class for association checkers
Direct Known Subclasses
ForeignKeyCascadeChecker, ForeignKeyChecker, ForeignKeyTypeChecker, MissingAssociationClassChecker, MissingDependentDestroyChecker, MissingIndexChecker
Instance Attribute Summary collapse
-
#association ⇒ Object
readonly
Returns the value of attribute association.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
- #column_or_attribute_name ⇒ Object
-
#foreign_key_exists? ⇒ Boolean
rubocop:disable Metrics/AbcSize.
-
#initialize(model, association) ⇒ AssociationChecker
constructor
A new instance of AssociationChecker.
- #table_or_model_name ⇒ Object
Methods inherited from BaseChecker
checker_name, enabled?, #enabled?, inherited, #report, #report_if_enabled?
Constructor Details
#initialize(model, association) ⇒ AssociationChecker
Returns a new instance of AssociationChecker.
13 14 15 16 17 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 13 def initialize(model, association) super() @model = model @association = association end |
Instance Attribute Details
#association ⇒ Object (readonly)
Returns the value of attribute association.
7 8 9 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 7 def association @association end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 7 def model @model end |
Class Method Details
.processor ⇒ Object
9 10 11 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 9 def self.processor Processors::AssociationsProcessor end |
Instance Method Details
#column_or_attribute_name ⇒ Object
19 20 21 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 19 def column_or_attribute_name @column_or_attribute_name ||= association.name.to_s end |
#foreign_key_exists? ⇒ Boolean
rubocop:disable Metrics/AbcSize
27 28 29 30 31 32 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 27 def foreign_key_exists? # rubocop:disable Metrics/AbcSize model.connection.foreign_keys(model.table_name).any? do |foreign_key| (Helper.extract_columns(association.foreign_key.to_s) - Array.wrap(foreign_key.column)).empty? && foreign_key.to_table == association.klass.table_name end end |
#table_or_model_name ⇒ Object
23 24 25 |
# File 'lib/database_consistency/checkers/association_checkers/association_checker.rb', line 23 def table_or_model_name @table_or_model_name ||= model.name.to_s end |