Skip to content

Commit 614c07a

Browse files
committed
fix polymorphic_type for ToOne relationships
1 parent 5eb0869 commit 614c07a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/jsonapi/relationship.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def belongs_to?
7474
end
7575

7676
def polymorphic_type
77-
"#{type.to_s.singularize}_type" if polymorphic?
77+
"#{name}_type" if polymorphic?
7878
end
7979
end
8080

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require File.expand_path('../../../test_helper', __FILE__)
2+
3+
class HasOneRelationshipTest < ActiveSupport::TestCase
4+
5+
def test_polymorphic_type
6+
relationship = JSONAPI::Relationship::ToOne.new("imageable",
7+
polymorphic: true
8+
)
9+
assert_equal(relationship.polymorphic_type, "imageable_type")
10+
end
11+
12+
end

0 commit comments

Comments
 (0)