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)

Constant Summary

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#descriptionObject (readonly)



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

validates :key, :name, :title, :description, :position, presence: true

#keyObject (readonly)



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

validates :key, :position, uniqueness: true

#nameObject (readonly)



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

validates :key, :name, :title, :description, :position, presence: true

#positionObject (readonly)



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

validates :key, :position, uniqueness: true

#titleObject (readonly)



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

validates :key, :name, :title, :description, :position, presence: true

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
  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
  (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?
  items.empty?
end