Skip to content

has_many :dependent => :destroy deleting associations on update_attributes #13217

@man2d

Description

@man2d

Here's the code:

class Operation < ActiveRecord::Base
  belongs_to :service
  has_many :errors, :dependent => :destroy

  attr_accessible :name, :disabled, :timeout
  validates_uniqueness_of :name, :scope => :service_id


  def to_s
    self.name
  end
end

class Error < ActiveRecord::Base
  belongs_to :operation
  has_many :errors, :through => :operation # here's the funny mistake 
 end

So when I call @operation.update_attributes it destroys all errors associated with operation. The question is - why?!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions