diff --git a/lib/jsonapi/basic_resource.rb b/lib/jsonapi/basic_resource.rb index bc18c96bf..edffb4ae1 100644 --- a/lib/jsonapi/basic_resource.rb +++ b/lib/jsonapi/basic_resource.rb @@ -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 diff --git a/test/controllers/controller_test.rb b/test/controllers/controller_test.rb index 74743de2f..fcc9a9819 100644 --- a/test/controllers/controller_test.rb +++ b/test/controllers/controller_test.rb @@ -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: []}