Class: ExclusiveItemGroup

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

Overview

== Schema Information

Table name: exclusive_item_groups
Database name: primary

id :integer not null, primary key
description :string
key :string
name :string
per_thermostat :boolean default(FALSE), not null
position :integer
title :string

Indexes

index_exclusive_item_groups_on_key (key)

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Class Method Details

.options_for_selectObject



25
26
27
# File 'app/models/exclusive_item_group.rb', line 25

def self.options_for_select
  ExclusiveItemGroup.order(:position).pluck(:name, :id)
end

Instance Method Details

#compact_positionsObject



33
34
35
36
37
# File 'app/models/exclusive_item_group.rb', line 33

def compact_positions
  self.order(:position).each_with_index do |o, i|
    o.update_column(:position, i)
  end
end

#itemsActiveRecord::Relation<Item>

Returns:

  • (ActiveRecord::Relation<Item>)

See Also:



20
# File 'app/models/exclusive_item_group.rb', line 20

has_many :items, -> { order(:sku) }, :inverse_of => :exclusive_item_group, :dependent => :nullify

#next_positionObject



29
30
31
# File 'app/models/exclusive_item_group.rb', line 29

def next_position
  (self.maximum(:position) || 0) + 1
end

#ok_to_delete?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/models/exclusive_item_group.rb', line 39

def ok_to_delete?
  self.items.empty?
end