Class: GeoLabels::Label

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

Constant Summary collapse

RANSACKABLE_ATTRIBUTES =
%w[name].freeze

Constants inherited from ApplicationRecord

ApplicationRecord::RANSACKABLE_ASSOCIATIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Class Method Details

.descendants_for_ids(ids) ⇒ Object



14
15
16
17
18
19
20
21
# File 'app/models/geo_labels/label.rb', line 14

def self.descendants_for_ids(ids)
  records = find(ids)
  descendants_scope = records.shift.self_and_descendants
  records.each do |record|
    descendants_scope = descendants_scope.or(record.self_and_descendants)
  end
  descendants_scope
end

Instance Method Details

#associated_contactsObject



23
24
25
26
# File 'app/models/geo_labels/label.rb', line 23

def associated_contacts
  ids = ContactLabel.joins(:label).merge(self_and_descendants).pluck(:contact_id).uniq
  Contact.order(:name).find(ids)
end