Skip to content

Commit 201426d

Browse files
authored
Merge pull request #1267 from cerebris/remove_relationship_use_delete
Revert "Use `destroy` instead of `delete` to ensure callbacks are called - master
2 parents b7a7990 + 436f062 commit 201426d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/jsonapi/basic_resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def _remove_to_many_link(relationship_type, key, options)
365365

366366
@reload_needed = true
367367
else
368-
@model.public_send(relationship.relation_name(context: @context)).destroy(key)
368+
@model.public_send(relationship.relation_name(context: @context)).delete(key)
369369
end
370370

371371
:completed

test/controllers/controller_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,25 @@ def test_update_relationship_to_one_singular_param
13961396
assert_equal ruby.id, post_object.section_id
13971397
end
13981398

1399+
def test_remove_relationship_to_many_belongs_to
1400+
set_content_type_header!
1401+
c = Comment.find(3)
1402+
p = Post.find(2)
1403+
total_comment_count = Comment.count
1404+
post_comment_count = p.comments.count
1405+
1406+
put :destroy_relationship, params: {post_id: "#{p.id}", relationship: 'comments', data: [{type: 'comments', id: "#{c.id}"}]}
1407+
1408+
assert_response :no_content
1409+
p = Post.find(2)
1410+
c = Comment.find(3)
1411+
1412+
assert_equal post_comment_count - 1, p.comments.length
1413+
assert_equal total_comment_count, Comment.count
1414+
1415+
assert_nil c.post_id
1416+
end
1417+
13991418
def test_update_relationship_to_many_join_table_single
14001419
set_content_type_header!
14011420
put :update_relationship, params: {post_id: 3, relationship: 'tags', data: []}

0 commit comments

Comments
 (0)