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

rails_admin kills Rails5's belongs_to default presence validation #2785

Closed
ordinaryzelig opened this issue Dec 3, 2016 · 0 comments · Fixed by #2786
Closed

rails_admin kills Rails5's belongs_to default presence validation #2785

ordinaryzelig opened this issue Dec 3, 2016 · 0 comments · Fixed by #2786

Comments

@ordinaryzelig
Copy link
Contributor

ordinaryzelig commented Dec 3, 2016

By default, Rails5's belongs_to now requires the association and creates a validation for its presence automatically. For some reason rails_admin kills this default.

To demonstrate: with a brand new rails 5.0.0.1 app, create a basic belongs_to relation:

class Tree < ApplicationRecord
end

class Branch < ApplicationRecord
  belongs_to :tree
end

In the console:

Branch.belongs_to_required_by_default
#=> true
Branch.validators
#=> [#<ActiveRecord::Validations::PresenceValidator:0x007faf72209a58 @attributes=[:tree], @options={:message=>:required}>]
Branch.new.tap(&:validate).errors.full_messages
#=> ["Tree must exist"]

After installing rails_admin gem and running installation generator, the same console commands:

Branch.belongs_to_required_by_default
#=> nil
Branch.validators
#=> []
Branch.new.tap(&:validate).errors.full_messages
#=> []
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.

1 participant