Skip to content

AssociationCollection#destroy should only delete join table records #602

@lighthouse-import

Description

@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/2251
Created by Luca Guidi - 2011-02-16 07:20:11 UTC

I opened this ticket as continuation of an off topic discussion in #2146
Martin Andert reported:

I found some unexpected behavior dealing with has_many :through associations. Given the following:

class Post < ActiveRecord::Base
  has_many :taggings
  has_many :tags, :through => :taggings
end

post = Post.first
tag = post.tags.first

Calling post.tags.delete(tag) removes the tagging from the database and leaves the tag intact.
But calling post.tags.destroy(tag) removes the tag from the database (not the tagging).
IMO, I don't expect destroy to delete the record from the database, only the through_association item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions