I'm trying to understand this relationship setup on this model, and why is this an issue on Rails 6.
Coming from Rails 3, this relationship is defined as:
belongs_to :entity foreign_key: 'user_id', foreign_type: 'ruby_type'
This worked fine, all the way up to Rails 5 (At least our crawl and traceroute did not bring this as an issue).
However, once we got to Rails 6, we found the following:
ArgumentError: Unknown key: :foreign_type. Valid keys are: :class_name, :anonymous_class, :primary_key, :foreign_key, :dependent, :validate, :inverse_of, :strict_loading, :autosave, :required, :touch, :polymorphic, :counter_cache, :optional, :default
Was this syntax changed for Rails 6?
foreign_type option can only be applied together with polymorphic - so make sure this is a polymorphic association you are after. If the association is not polymorphic I would get rid of foreign_type.
belongs_to :entity, foreign_key: 'user_id', foreign_type: 'ruby_type', polymorphic: true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With