Skip to content

Commit 05dc13f

Browse files
authored
Merge pull request rails#41098 from kamipo/fix_source_type_with_symbol
Fix "NoMethodError: undefined method `-@'" for `source_type` with a symbol
2 parents f1b923b + 8b3c38f commit 05dc13f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

activerecord/lib/active_record/reflection.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def build_association(attributes, &block)
162162
# <tt>composed_of :balance, class_name: 'Money'</tt> returns <tt>'Money'</tt>
163163
# <tt>has_many :clients</tt> returns <tt>'Client'</tt>
164164
def class_name
165-
@class_name ||= -(options[:class_name]&.to_s || derive_class_name)
165+
@class_name ||= -(options[:class_name] || derive_class_name).to_s
166166
end
167167

168168
# Returns a list of scopes that should be applied for this Reflection

activerecord/test/models/club.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Club < ActiveRecord::Base
55
has_many :memberships, inverse_of: false
66
has_many :members, through: :memberships
77
has_one :sponsor
8-
has_one :sponsored_member, through: :sponsor, source: :sponsorable, source_type: "Member"
8+
has_one :sponsored_member, through: :sponsor, source: :sponsorable, source_type: :Member
99
belongs_to :category
1010

1111
has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member

0 commit comments

Comments
 (0)