Class: Notee::Category

Inherits:
ApplicationRecord show all
Defined in:
app/models/notee/category.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

#create_authority, #destroy_authority, #is_destroy?, #update_authority

Class Method Details

.before_destroy_parent(id) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/notee/category.rb', line 35

def self.before_destroy_parent(id)
  @child_with_parent =Category.where(parent_id: id)

  Category.skip_callback(:update, :before, :update_authority)
  Category.skip_callback(:update, :before, :destroy_authority)
  @child_with_parent.each do |child|
    child.update(parent_id: nil)
  end
  Category.set_callback(:update, :before, :update_authority)
  Category.set_callback(:update, :before, :destroy_authority)
end