Class: Dscf::Marketplace::Category

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



20
21
22
# File 'app/models/dscf/marketplace/category.rb', line 20

def self.ransackable_associations(_auth_object = nil)
  %w[parent subcategories products]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object

Ransack configuration for secure filtering



16
17
18
# File 'app/models/dscf/marketplace/category.rb', line 16

def self.ransackable_attributes(_auth_object = nil)
  %w[id name description parent_id created_at updated_at]
end

Instance Method Details

#descendantsObject



28
29
30
31
32
33
34
35
# File 'app/models/dscf/marketplace/category.rb', line 28

def descendants
  descendants = []
  subcategories.each do |subcategory|
    descendants << subcategory
    descendants.concat(subcategory.descendants)
  end
  descendants
end

#root?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/dscf/marketplace/category.rb', line 24

def root?
  parent_id.nil?
end