summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2018-05-11 11:19:59 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2018-05-11 11:19:59 +1100
commitc3e40ed8ff0b2d0d9260667ec7825453af0bd6f3 (patch)
treed37a1b911d574ced45fa201321adfa5c0bcc76e9
parent35816eb7be76aa1a26dcf2f9cfeddf7c60b2da26 (diff)
downloadgitlab-ce-blackst0ne-rails5-fix-route-source-can-t-be-blank.tar.gz
[Rails5] Fix `Route source can't be blank`blackst0ne-rails5-fix-route-source-can-t-be-blank
In Rails 5.0 automatic inverse does not work for polymorphic relathionships. It was fixed in Rails 5.2: https://github.com/rails/rails/pull/28808 Until that the `inverse_of: :source` argument should be set explicitly.
-rw-r--r--app/models/concerns/routable.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/app/models/concerns/routable.rb b/app/models/concerns/routable.rb
index 915ad6959be..0176a12a131 100644
--- a/app/models/concerns/routable.rb
+++ b/app/models/concerns/routable.rb
@@ -4,7 +4,9 @@ module Routable
extend ActiveSupport::Concern
included do
- has_one :route, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
+ # Remove `inverse_of: source` when upgraded to rails 5.2
+ # See https://github.com/rails/rails/pull/28808
+ has_one :route, as: :source, autosave: true, dependent: :destroy, inverse_of: :source # rubocop:disable Cop/ActiveRecordDependent
has_many :redirect_routes, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
validates :route, presence: true