Skip to content

Commit a3ffb36

Browse files
author
Kyle d'Oliveira
committed
If we cannot find the class with the to_s version of the class name, fall back to using the sti_name of the class which can be different
1 parent dc3fb4d commit a3ffb36

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/polymorphic_integer_type/extensions.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def belongs_to(name, scope = nil, **options)
3131

3232
define_method "#{foreign_type}=" do |klass|
3333
enum = mapping.key(klass.to_s)
34-
enum ||= mapping.key(klass.base_class.to_s) if klass.kind_of?(Class) && klass <= ActiveRecord::Base
34+
if klass.kind_of?(Class) && klass <= ActiveRecord::Base
35+
enum ||= mapping.key(klass.base_class.to_s)
36+
enum ||= mapping.key(klass.base_class.sti_name)
37+
end
3538
enum ||= klass if klass != NilClass
3639
super(enum)
3740
end

0 commit comments

Comments
 (0)