Commit c3e40ed8 authored by blackst0ne's avatar 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.
parent 35816eb7
...@@ -4,7 +4,9 @@ module Routable ...@@ -4,7 +4,9 @@ module Routable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do 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 has_many :redirect_routes, as: :source, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
validates :route, presence: true validates :route, presence: true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment