Skip to content

Conversation

@gregnavis
Copy link
Owner

This commits rewrites missing_presence_validation in a more imperative style with extensive commenting to make it clear why certain actions are performed. The new structure made it simple to correctly handle polymorphic associations: if a polymorphic foreign key is NOT NULL then the detector will suggest making the association as required, instead of suggesting adding validators for the _id and _type column separately.

This commits rewrites missing_presence_validation in a more imperative
style with extensive commenting to make it clear why certain actions are
performed. The new structure made it simple to correctly handle
polymorphic associations: if a polymorphic foreign key is NOT NULL then
the detector will suggest making the association as required, instead of
suggesting adding validators for the _id and _type column separately.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR rewrites the missing_presence_validation detector to handle polymorphic associations correctly by suggesting association-level validation instead of separate validators for foreign key and type columns.

  • Rewrote the detector logic in a more imperative style with extensive commenting for better maintainability
  • Added proper handling for polymorphic associations to suggest optional: false instead of separate column validators
  • Added test coverage for polymorphic association scenarios and configuration options

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/setup.rb Sets default Rails behavior for belongs_to associations to be required by default
test/active_record_doctor/detectors/missing_presence_validation_test.rb Adds comprehensive test coverage for polymorphic association validation scenarios
lib/active_record_doctor/detectors/missing_presence_validation.rb Complete rewrite of the detector logic to handle polymorphic associations and improve code clarity

@gregnavis gregnavis merged commit 998780b into master Aug 5, 2025
80 checks passed
@gregnavis gregnavis deleted the 163-missing-presence-validation-on-polymorphic-associations branch August 5, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

false positive An error is reported when it shouldn't

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants