Class: BanalComplex

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

Overview

typed: true

Instance Method Summary collapse

Instance Method Details

#calculate_and_save_combined_weight!Object



13
14
15
# File 'app/models/banal_complex.rb', line 13

def calculate_and_save_combined_weight!
    update_column(:weight_of_identity_plus_children, self.descendants.map(&:weight).sum)
end

#delete_childrensObject



8
9
10
# File 'app/models/banal_complex.rb', line 8

def delete_childrens
    self.children.destroy_all
end

#descendantsObject

fails as a ruby keyword mayb? like §Fails as a directive like §Idempotent



18
19
20
21
22
23
24
25
26
27
# File 'app/models/banal_complex.rb', line 18

def descendants
    first_level_children = self.class.where(parent_id: self.id)
    second_level_children = first_level_children
        .pluck(:id)
        .reject { |id| id == self.id }
        .tap { |ids| puts ids.inspect + self.inspect }
        .map { |id| self.class.where(parent_id: id) }.flatten

    first_level_children + second_level_children
end