Class: ExclusiveItemGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ExclusiveItemGroup
- 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
Class Method Details
.options_for_select ⇒ Object
25 26 27 |
# File 'app/models/exclusive_item_group.rb', line 25 def self. 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 self.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 (self.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? self.items.empty? end |