her
her copied to clipboard
Cannot remove resource on association
It doesn't seem to be possible to remove a resource on an association. In case of a many-to-many relation, no one holds the foreign key of the other and thus it cannot be changed with simple PUTs on the non associated resources.
user = User.find(1)
user.comments # => [#<Comment(comments/1) body="Cool!" user_id=1 id=1 user=#<User(users/1) id=1 comments=[...]>>, #<Comment(comments/2) ...>]
user.comments.count # => 2
user.comments.destroy_existing(2) # => #<Comment(comments/2) ...>
user.comments # => [#<Comment(comments/1) body="Cool!" user_id=1 id=1 user=#<User(users/1) id=1 comments=[...]>>
user.comments.count # => 1]
I have actually know idea what usage of #destroy would look like.
The problem that I cannot do user.comments.last.destroy as it will destroy comment with ID 2 all together instead of just the association of the user with the comment.