Skip to content

ActiveRecord belongs_to setting: optional: true where needed #2249

@olleolleolle

Description

@olleolleolle

While upgrading Rails, at one time, we didn't change to all the new default behaviors, but we auto-enabled the old behavior, postponing some work. This Issue is about such a chore.

Step 1: disable this "automatic optional" setting in config/application.rb

    # TODO: sort this out properly at 
    # See https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#active-record-belongs-to-required-by-default-option
    config.active_record.belongs_to_required_by_default = false

Step 2: in each model's belongs_to associations, decide whether that is an optional relationship or not. Where it is optional, add the keyword argument optional: true.

Step 3: pass all tests, and you are done!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions