You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the short term, we can fall back to the old behavior by setting config.active_record.belongs_to_required_validates_foreign_key to true (thus unconditionally defining the validation), but my understanding is that this is a short-lived config to support backwards compatibility, and besides, the new behavior is a performance improvement.
Assuming y'all agree this is something that should be fixed (rather than, say, defining the redundant validation, passing required: true to the field in the form, or something else), I'd be happy to work on a patch if I could get some guidance. Something like
- validator.options.include?(:if) || validator.options.include?(:unless) + if validator.options.include?(:if)+ file_path, line_number = validator.options[:if].source_location+ !file_path.match?(%r{lib/active_record/associations/builder/belongs_to.rb}) && line_number != 130+ else+ validator.options.include?(:unless)+ end
would obviously work but be incredibly hacky. How would we want to approach a more robust way to allow this particular conditional validation where the item should always be present?
The text was updated successfully, but these errors were encountered:
Environment
Current behavior
By default, on rails 7.1+,
belongs_to
relationships do not show up as required.Sample App
This works if we add a redundant
validates :user, presence: true
.Expected behavior
belongs_to
relationships should show up as requiredDetails
This is due to an interaction between how we calculate required, specifically at
simple_form/lib/simple_form/helpers/validators.rb
Line 24 in c2c7faf
In the short term, we can fall back to the old behavior by setting config.active_record.belongs_to_required_validates_foreign_key to true (thus unconditionally defining the validation), but my understanding is that this is a short-lived config to support backwards compatibility, and besides, the new behavior is a performance improvement.
Assuming y'all agree this is something that should be fixed (rather than, say, defining the redundant validation, passing
required: true
to the field in the form, or something else), I'd be happy to work on a patch if I could get some guidance. Something likewould obviously work but be incredibly hacky. How would we want to approach a more robust way to allow this particular conditional validation where the item should always be present?
The text was updated successfully, but these errors were encountered: