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/basic_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _remove_to_many_link(relationship_type, key, options)

@reload_needed = true
else
@model.public_send(relationship.relation_name(context: @context)).destroy(key)
@model.public_send(relationship.relation_name(context: @context)).delete(key)
end

:completed
Expand Down
19 changes: 19 additions & 0 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,25 @@ def test_update_relationship_to_one_singular_param
assert_equal ruby.id, post_object.section_id
end

def test_remove_relationship_to_many_belongs_to
set_content_type_header!
c = Comment.find(3)
p = Post.find(2)
total_comment_count = Comment.count
post_comment_count = p.comments.count

put :destroy_relationship, params: {post_id: "#{p.id}", relationship: 'comments', data: [{type: 'comments', id: "#{c.id}"}]}

assert_response :no_content
p = Post.find(2)
c = Comment.find(3)

assert_equal post_comment_count - 1, p.comments.length
assert_equal total_comment_count, Comment.count

assert_nil c.post_id
end

def test_update_relationship_to_many_join_table_single
set_content_type_header!
put :update_relationship, params: {post_id: 3, relationship: 'tags', data: []}
Expand Down