Customize Delegated Type's type column

Delegated Types leans heavily on Rails’ existing polymorphic associations. The primary association created by delegated_type is a polymorphic belongs_to association.

For apps that are using polymorphic associations but need to customize the column containing the type/class, foreign_type is available as an option. It would be helpful if the same customization were available for Delegated Types.

Since delegated_types already passes its options along to the underlying belongs_to association, this is a relatively straightforward change. Instead of only deriving the type column by using "#{role}_type", it can respect a foreign_type option. (Same option key as used by polymorphic associations.)

I have validated this customization works in an existing Rails app and have made the change in my fork of Rails. Happy to open as a PR (including documentation in via comments).

Example:

delegated_type :entryable, types: %w[ Message Comment ], foreign_type: :entry_class

Working branch: https://github.com/rails/rails/compare/main...jasonkarns:delegated-type-column

PR open: https://github.com/rails/rails/pull/45041