Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/jsonapi/relationship.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def belongs_to?
end

def polymorphic_type
"#{type.to_s.singularize}_type" if polymorphic?
"#{name}_type" if polymorphic?
end
end

Expand Down
12 changes: 12 additions & 0 deletions test/unit/resource/relationship_test.rb
Original file line number Diff line number Diff line change
@@ -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