[openstreetmap/openstreetmap-website] Enable active_record.belongs_to_required_by_default (PR #3470)

Andy Allan notifications at github.com
Wed Feb 23 15:33:37 UTC 2022


This switches the logic so that `belongs_to` parent objects must exist by default, and marks the optional ones explicitly. This is reflected in the null/not_null status on the relevant db columns.

Doing this exposed a small corner case where we were relying on the previous default (of everything being optional) in order for trace objects to pass validation. When the `belongs_to` was made required by default, rails couldn't autodetect the inverse relationship, and so thought that all tracetags for new traces were invalid. Adding inverse_of fixed this. See also https://guides.rubyonrails.org/association_basics.html#bi-directional-associations for a better explanation.
You can view, comment on, or merge this pull request online at:

  https://github.com/openstreetmap/openstreetmap-website/pull/3470

-- Commit Summary --

  * Specify inverse_of for trace tags and points
  * Enable active_record.belongs_to_required_by_default

-- File Changes --

    M app/models/access_token.rb (4)
    M app/models/client_application.rb (2)
    M app/models/issue.rb (6)
    M app/models/note_comment.rb (2)
    M app/models/oauth_token.rb (4)
    M app/models/old_node.rb (2)
    M app/models/old_relation.rb (2)
    M app/models/old_way.rb (2)
    M app/models/trace.rb (4)
    M app/models/user_block.rb (2)
    M config/application.rb (4)

-- Patch Links --

https://github.com/openstreetmap/openstreetmap-website/pull/3470.patch
https://github.com/openstreetmap/openstreetmap-website/pull/3470.diff

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/3470
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/3470 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20220223/37e1df4f/attachment.htm>


More information about the rails-dev mailing list