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 missing_non_null_constraint when there are no STI children for STI-like parent #139

Conversation

fatkodima
Copy link
Contributor

When the STI-like parent model has no children, all the next branches in the detect method pass (specifically next if !concrete_models.all? { |model| non_null_needed?(model, column) }) and MissingNonNullConstraint erroneously adds offenses for the column. See a test case for the example.

@gregnavis gregnavis force-pushed the master branch 2 times, most recently from 168d951 to d322a6e Compare October 20, 2023 14:24
@gregnavis
Copy link
Owner

@fatkodima, I don't believe this PR is correct. I think it's perfectly valid to instantiate the base class of an STI hierarchy: in this case type will be nil. A subclass of the STI base class will have its name stored in type.

A proper fix for the problem would be to skip the check on the type column.

@fatkodima fatkodima force-pushed the fix-missing_non_null_constraint-when-no-sti-child branch from dca8fb3 to 36ff5f2 Compare August 27, 2024 15:06
@fatkodima
Copy link
Contributor Author

Agreed, fixed.

@gregnavis
Copy link
Owner

Perfect! Thank you, @fatkodima.

@gregnavis gregnavis merged commit 8e641c9 into gregnavis:master Aug 27, 2024
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants