diff --git a/lib/jsonapi/relationship.rb b/lib/jsonapi/relationship.rb index 74c739bc8..0108e8985 100644 --- a/lib/jsonapi/relationship.rb +++ b/lib/jsonapi/relationship.rb @@ -74,7 +74,7 @@ def belongs_to? end def polymorphic_type - "#{type.to_s.singularize}_type" if polymorphic? + "#{name}_type" if polymorphic? end end diff --git a/test/unit/resource/relationship_test.rb b/test/unit/resource/relationship_test.rb new file mode 100644 index 000000000..8208933e4 --- /dev/null +++ b/test/unit/resource/relationship_test.rb @@ -0,0 +1,12 @@ +require File.expand_path('../../../test_helper', __FILE__) + +class HasOneRelationshipTest < ActiveSupport::TestCase + + def test_polymorphic_type + relationship = JSONAPI::Relationship::ToOne.new("imageable", + polymorphic: true + ) + assert_equal(relationship.polymorphic_type, "imageable_type") + end + +end