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
Constants included
from Schedulable
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 ⇒ Object
23
|
# File 'app/models/exclusive_item_group.rb', line 23
validates :key, :name, :title, :description, :position, presence: true
|
#key ⇒ Object
22
|
# File 'app/models/exclusive_item_group.rb', line 22
validates :key, :position, uniqueness: true
|
#name ⇒ Object
23
|
# File 'app/models/exclusive_item_group.rb', line 23
validates :key, :name, :title, :description, :position, presence: true
|
#position ⇒ Object
22
|
# File 'app/models/exclusive_item_group.rb', line 22
validates :key, :position, uniqueness: true
|
#title ⇒ Object
23
|
# File 'app/models/exclusive_item_group.rb', line 23
validates :key, :name, :title, :description, :position, presence: true
|
Class Method Details
.options_for_select ⇒ Object
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_positions ⇒ Object
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
|
#items ⇒ ActiveRecord::Relation<Item>
20
|
# File 'app/models/exclusive_item_group.rb', line 20
has_many :items, -> { order(:sku) }, inverse_of: :exclusive_item_group, dependent: :nullify
|
#next_position ⇒ Object
29
30
31
|
# File 'app/models/exclusive_item_group.rb', line 29
def next_position
(maximum(:position) || 0) + 1
end
|
#ok_to_delete? ⇒ Boolean
39
40
41
|
# File 'app/models/exclusive_item_group.rb', line 39
def ok_to_delete?
items.empty?
end
|