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

Use ActiveSupport.on_load to correctly re-open ActiveRecord::Base #371

Merged
merged 1 commit into from
Dec 13, 2016
Merged

Use ActiveSupport.on_load to correctly re-open ActiveRecord::Base #371

merged 1 commit into from
Dec 13, 2016

Conversation

iaankrynauw
Copy link
Contributor

#335

I don't really know how to write a test for this. Although I have checked that it fixes the issue.

In Rails5 Rails.application.config.active_record.belongs_to_required_by_default = true gets added in new_framework_defaults.rb.

When opening ActiveRecord::Base this gets overridden and requires belongs_to model, required: true.

The fix waits for ActiveSupport.on_load(:active_record) to load before opening ActiveRecord::Base.

class ParanoidModel < ActiveRecord::Base
  belongs_to :parent_model
  acts_as_paranoid
end

expect(ParanoidModel.create).to_not be_valid
expect(ParanoidModel.create(parent_model_id: 1)).to be_valid

@BenMorganIO BenMorganIO merged commit 6972b22 into rubysherpas:core Dec 13, 2016
@BenMorganIO
Copy link
Collaborator

Thanks @iaankrynauw 👍

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