Class: ExclusiveItemGroup
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
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
config
#after_commit
#publish_event
Instance Attribute Details
#description ⇒ String
32
|
# File 'app/models/exclusive_item_group.rb', line 32
validates :description, presence: true
|
#key ⇒ String
24
|
# File 'app/models/exclusive_item_group.rb', line 24
validates :key, uniqueness: true, presence: true
|
#name ⇒ String
28
|
# File 'app/models/exclusive_item_group.rb', line 28
validates :name, presence: true
|
#position ⇒ Integer
26
|
# File 'app/models/exclusive_item_group.rb', line 26
validates :position, uniqueness: true, presence: true
|
#title ⇒ String
30
|
# File 'app/models/exclusive_item_group.rb', line 30
validates :title, presence: true
|
Class Method Details
.options_for_select ⇒ Array<Array<String, Integer>>
35
36
37
|
# File 'app/models/exclusive_item_group.rb', line 35
def self.options_for_select
ExclusiveItemGroup.order(:position).pluck(:name, :id)
end
|
Instance Method Details
#compact_positions ⇒ void
This method returns an undefined value.
45
46
47
48
49
|
# File 'app/models/exclusive_item_group.rb', line 45
def compact_positions
order(:position).each_with_index do |o, i|
o.update_column(:position, i)
end
end
|
#items ⇒ ActiveRecord::Relation<Item>
21
|
# File 'app/models/exclusive_item_group.rb', line 21
has_many :items, -> { order(:sku) }, inverse_of: :exclusive_item_group, dependent: :nullify
|
#next_position ⇒ Integer
40
41
42
|
# File 'app/models/exclusive_item_group.rb', line 40
def next_position
(maximum(:position) || 0) + 1
end
|
#ok_to_delete? ⇒ Boolean
52
53
54
|
# File 'app/models/exclusive_item_group.rb', line 52
def ok_to_delete?
items.empty?
end
|