JackDanger / permanent_records

Rails Plugin - soft-delete your ActiveRecord records. It's like an explicit version of ActsAsParanoid
https://jdanger.com
MIT License
272 stars 64 forks source link

Fixes a bug for single table inheritence #70

Closed aq closed 8 years ago

aq commented 8 years ago

Those lines replaced all the attributes of a record during a soft destroy:

class Branche < ActiveRecord::Base
  include ActiveRecord::SoftDestroyable
  has_many :sub_branches, foreign_key: 'parent_id', class_name: 'Branche'
  belongs_to :main_branche, foreign_key: 'parent_id', class_name: 'Branche'
end
main_branche = Branche.create
main_branche.id # => 1
sub_branche = Branche.create parent_id: main_branche.id
sub_branche.id # => 2
sub_branche.destroy!
sub_branche.id # => ! 1 in place of 2
 # because the instance attributes have been replaced.

The spec was a false positive because the relation between hole and location is has_one not has_many:

JackDanger commented 8 years ago

Awesome work! Merging!

JackDanger commented 8 years ago

I've pushed gem version 4.1.5 with your changes and added your Github username as an author. Thanks, @aq !