Class: Mdm::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/mdm/tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostsActiveRecord::Relation<Mdm::Host> (readonly)

Host that are tagged with this tag.

Returns:



27
# File 'app/models/mdm/tag.rb', line 27

has_many :hosts, :through => :hosts_tags, :class_name => 'Mdm::Host'

#hosts_tagsActiveRecord::Relation<Mdm::HostTag>

Joins #hosts to this tag.

Returns:



10
11
12
13
# File 'app/models/mdm/tag.rb', line 10

has_many :hosts_tags,
class_name: 'Mdm::HostTag',
dependent: :destroy,
inverse_of: :tag

Instance Method Details

#destroy_if_orphanedvoid

This method returns an undefined value.

Destroy this tag if it has no #hosts_tags



52
53
54
55
56
57
58
# File 'app/models/mdm/tag.rb', line 52

def destroy_if_orphaned
  self.class.transaction do
    if hosts_tags.empty?
      destroy
    end
  end
end

#to_sObject



60
61
62
# File 'app/models/mdm/tag.rb', line 60

def to_s
  name
end