-
Notifications
You must be signed in to change notification settings - Fork 57
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
Missing Presence Validation with Polymorphic Type Column #163
Comments
@Numie, I think what's wrong here is that the error message should be different: it should tell you to add Please double-check this, but I think if you do the following: model = YourModel.new(documentable: nil)
model.validate Then you won't find an error on documentable. |
|
@fatkodima, you're right. I was confused by the fact that belongs_to seem not to be required by default in active_record_doctor test suite. For example, when I took your PR and made the following change: def test_non_null_column_is_not_reported_if_polymorphic_association_validation_present
Context.create_table(:images) do |t|
t.references :imageable, null: false, polymorphic: true
end.define_model do
# I removed required from the association.
belongs_to :imageable, polymorphic: true
end
refute_problems
end Then I got an error:
Are you able to reproduce it on your end? |
Yes, I get the same error with your changes.
So we need to add to ActiveRecord::Base.belongs_to_required_by_default = true or leave a |
Thanks for the link. Sadly, it seems the default is not set within the active record gem. I prefer not to add an explicit dependency on the |
I have a polymorphic association like:
There are
not_null
db constraints on the relateddocumentable_id
anddocumentable_type
columns. When I runactive_record_doctor
, I get the following error:I don't think an error should be raised since ActiveRecord already requires both the type and id columns from the single
belongs_to
association.The text was updated successfully, but these errors were encountered: