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

Installing gem breaks ActiveRecord 5 default 'required' behaviour #335

Closed
lukeredpath opened this issue Jun 23, 2016 · 11 comments · Fixed by fsek/web#743
Closed

Installing gem breaks ActiveRecord 5 default 'required' behaviour #335

lukeredpath opened this issue Jun 23, 2016 · 11 comments · Fixed by fsek/web#743

Comments

@lukeredpath
Copy link

In Rails 5, associations are required by default.

After installing the paranoia gem, all of my specs that test this behaviour fail. I haven't explicitly required it anywhere (it is required by bundler) and I haven't added acts_as_paranoid to any of my models.

I can fix my specs by explicitly adding required: true to my associations but this should not be necessary.

@lukeredpath
Copy link
Author

I'm going to go ahead and close this as this is not a paranoid specific bug - having narrowed it down it seems the cause is the re-opening of the ActiveRecord::Base class at some stage of the Rails initialisation process.

I was able to reproduce the issue simply by re-opening the class in my Rails application.rb:

require 'rails/all'

class ActiveRecord::Base
end

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

@fusion2004
Copy link

fusion2004 commented Jul 3, 2016

It looks like the recommendation from @rafaelfranca is to use ActiveSupport.on_load(:active_record), rather than re-opening the class. In order to implement, we'll need to add ActiveSupport as a dependency to paranoia.

If that sounds like an acceptable solution to the paranoia maintainer(s), I or someone else can make a PR implementing that.

@BenMorganIO
Copy link
Collaborator

@fusion2004 if you could make a PR, that would be awesome :)

@fusion2004
Copy link

fusion2004 commented Jul 12, 2016

@BenMorganIO Sure, I will take a crack at it by tomorrow night.

@connorshea
Copy link

@fusion2004 any updates on this?

@iaankrynauw
Copy link
Contributor

iaankrynauw commented Dec 9, 2016

For easy access to a solution:

Moving Rails.application.config.active_record.belongs_to_required_by_default = true from new_framework_defaults.rb to application.rb seems to resolve the problem.

The above issue referenced says it's an initialization order issue and from what I gather it's not necessarily a paranoia issue.

@BenMorganIO
Copy link
Collaborator

@iaankrynauw if that's so, would it be OK to close this issue then?

@BenMorganIO
Copy link
Collaborator

@fusion2004 if you'd still like to submit a patch, that'd be nice too ;)

@iaankrynauw
Copy link
Contributor

Looks to me like @fusion2004's ActiveSupport.on_load(:active_record) response will solve it. I'll look into it on Monday try and resolve this.

@BenMorganIO
Copy link
Collaborator

@iaankrynauw Thanks 👍

@BenMorganIO
Copy link
Collaborator

See #371

thromera added a commit to thromera/paranoia that referenced this issue Feb 7, 2017
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
thromera added a commit to thromera/paranoia that referenced this issue Feb 7, 2017
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
thromera added a commit to thromera/paranoia that referenced this issue Feb 7, 2017
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
thromera added a commit to thromera/paranoia that referenced this issue Feb 7, 2017
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
thromera added a commit to thromera/paranoia that referenced this issue Feb 14, 2017
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
karunkumar1ly pushed a commit to edcast/paranoia that referenced this issue Feb 6, 2024
…od and joining tables that have a scope on `with_deleted`

Update homepage in gemspec

The homepage is supposed to be where you can find the code. It is displayed on rubygems.org page. Currently it will redirect you back to the same page. Should point at this github repo.

Update README to use proper version for Rails 5

Version 2.2.0

Ignore failures from all jruby's on travis

Add explicit language about dependent: :destroy

Update CHANGELOG.md

update ruby and rails versions

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

Touch record on paranoia-destroy. Fixes rubysherpas#296

Touch record on destroy by leveraging the paranoia_destroy_attributes.
Applied the same to the restore-method as this eliminates the extra query.
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 a pull request may close this issue.

5 participants