Sha256: 64ef449a2e84e7379b87741caebc10042ca47cf92eb6750159125dff8e5fd6c3

Contents?: true

Size: 761 Bytes

Versions: 3

Compression:

Stored size: 761 Bytes

Contents

module Spree
  class OptionType < Spree::Base
    has_many :option_values, -> { order(:position) }, dependent: :destroy, inverse_of: :option_type
    has_many :product_option_types, dependent: :destroy, inverse_of: :option_type
    has_many :products, through: :product_option_types
    has_and_belongs_to_many :prototypes, join_table: 'spree_option_types_prototypes'

    validates :name, :presentation, presence: true
    default_scope -> { order("#{self.table_name}.position") }

    accepts_nested_attributes_for :option_values, reject_if: lambda { |ov| ov[:name].blank? || ov[:presentation].blank? }, allow_destroy: true

    after_touch :touch_all_products

    def touch_all_products
      products.update_all(updated_at: Time.current)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_core-2.4.0.rc3 app/models/spree/option_type.rb
spree_core-2.4.0.rc2 app/models/spree/option_type.rb
spree_core-2.4.0.rc1 app/models/spree/option_type.rb