Specify dynamic inverse_of for DataFields
This change allows this code block https://gitlab.com/gitlab-org/gitlab/-/blob/6773ed573be1ba8edee6028705502a5c47c88a87/app/models/integration.rb#L246-249 to continue working after the `Service` class was renamed `Integration`. Previously the code was working due to Rails' ability to guess the `inverse_of` relationship. From https://api.rubyonrails.org/v6.1.3.1/classes/ActiveRecord/Associations/ClassMethods.html "By default, Active Record can guess the inverse of the association based on the name of the class." When `Service` was renamed `Integration` this code began to fail, as `data_fields.integration = integration` would no longer magically link `integration.data_fields`. This is also mentioned in https://www.viget.com/articles/exploring-the-inverse-of-option-on-rails-model-associations/ "Obviously, this falls apart when the names do not match up. For example, when using :class_name or :foreign_key options on your associations. In that case, :inverse_of has to be explicitly set to the correct names". The `inverse_of` relationship needs to be dynamic to reflect the names of the `has_one` associations https://gitlab.com/gitlab-org/gitlab/-/blob/6773ed573be1ba8edee6028705502a5c47c88a87/app/models/project_services/data_fields.rb#L45-47
Showing
Please register or sign in to comment