Method: ForemanPuppet::Puppetclass#hostgroup_ids=

Defined in:
app/models/foreman_puppet/puppetclass.rb

#hostgroup_ids=(hg_ids) ⇒ Object

We are going through two associations, so we are on our own to define modifiers



121
122
123
124
125
126
127
# File 'app/models/foreman_puppet/puppetclass.rb', line 121

def hostgroup_ids=(hg_ids)
  hg_ids = Array(hg_ids).reject(&:blank?)
  hg_to_facets_ids = HostgroupPuppetFacet.where(hostgroup_id: hg_ids).pluck(:hostgroup_id, :id).to_h
  missing_facet_ids = hg_ids.map(&:to_i) - hg_to_facets_ids.keys
  new_facet_ids = missing_facet_ids.map { |hg_id| HostgroupPuppetFacet.create(hostgroup_id: hg_id).id }
  self.hostgroup_puppet_facet_ids = hg_to_facets_ids.values + new_facet_ids
end