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

friendly_id breaks ActiveRecord::Base.belongs_to_required_by_default in Rails 5.0.0 #730

Open
nflorentin opened this issue Feb 10, 2016 · 10 comments
Labels

Comments

@nflorentin
Copy link

In Rails 5.0.0, a new config was introduced to activate deactivate the automatic presence validation on belongs_to associations.

In config/active_record_belongs_to_required_by_default.rb:
Rails.application.config.active_record.belongs_to_required_by_default = true

Without friendly_id in gemfile

> Rails.application.config.active_record.belongs_to_required_by_default
=> true
> ActiveRecord::Base.belongs_to_required_by_default
=> true
> User.belongs_to_required_by_default
=> true

After adding friendly_id in gemfile

In rails console:

> Rails.application.config.active_record.belongs_to_required_by_default
=> true
> ActiveRecord::Base.belongs_to_required_by_default
=> nil
> User.belongs_to_required_by_default
=> nil
@nflorentin
Copy link
Author

As a temporary fix, you can replace Rails.application.config.active_record.belongs_to_required_by_default = true with ActiveRecord::Base.belongs_to_required_by_default = true in config/initializers/active_record_belongs_to_required_by_default.rb but I'm not sure if that could produce any side effect.

@kimrgrey
Copy link
Contributor

Hi, @nflorentin! Sounds weird, because, as I know, friendly_id doesn't do anything with this config. It looks like a side effect of something. I'll take a look on this issue.

@arokettu
Copy link

@kimrgrey from Rails issue referenced above:

This is due to initialization order. Any plugin that loads AR will cause it to pull config to AR::Base so subsequent initializers will be too late in the game to take effect.

You may close this one

@jprinaldi
Copy link

So why was this issue closed? Is there no way FriendlyId can prevent this from happening?

@edwardmp
Copy link

I agree with @juampi, that this issue is not resolved and friendly_id should be modified to adapt for this and thus the issue shouldn't be considered closed

@nflorentin
Copy link
Author

Here an example of a similar issue addressed for devise heartcombo/devise@c2c74b0

@edwardmp
Copy link

@nflorentin great, thanks for linking. Let me try If I can apply this to friendly_id too and submit a PR :)

@jeffblake
Copy link

Any luck on this?

@nflorentin
Copy link
Author

The issue is still there in version 5.4.2.

@nflorentin nflorentin reopened this Mar 25, 2022
@stale
Copy link

stale bot commented Nov 13, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants