Class: Decidim::Scope

Inherits:
ApplicationRecord show all
Defined in:
decidim-core/app/models/decidim/scope.rb

Overview

Scopes are used in some entities through Decidim to help users know which is the scope of a participatory process. (i.e. does it affect the whole city or just a district?)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.top_levelObject

Scope to return only the top level scopes.

Returns an ActiveRecord::Relation.



41
42
43
# File 'decidim-core/app/models/decidim/scope.rb', line 41

def self.top_level
  where parent_id: nil
end

Instance Method Details

#descendantsObject



45
46
47
# File 'decidim-core/app/models/decidim/scope.rb', line 45

def descendants
  organization.scopes.where("? = ANY(decidim_scopes.part_of)", id)
end

#part_of_scopesObject

Gets the scopes from the part_of list

Returns an ActiveRecord::Relation.



52
53
54
# File 'decidim-core/app/models/decidim/scope.rb', line 52

def part_of_scopes
  organization.scopes.where(id: part_of)
end