Sha256: b42fe9c14a68bae44abbc7ac5243325cfcdd95453f53d8441eebdb1dfaaf8172

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

module Spree
  class OptionValue < Spree::Base
    belongs_to :option_type, class_name: 'Spree::OptionType', touch: true, inverse_of: :option_values
    acts_as_list scope: :option_type

    has_many :option_values_variants, dependent: :destroy
    has_many :variants, through: :option_values_variants

    validates :name, presence: true, uniqueness: { scope: :option_type_id }
    validates :presentation, presence: true

    after_touch :touch_all_variants

    # Updates the updated_at column on all the variants associated with this
    # option value.
    def touch_all_variants
      variants.update_all(updated_at: Time.current)
    end

    # @return [String] a string representation of all option value and its
    #   option type
    def presentation_with_option_type
      "#{self.option_type.presentation} - #{self.presentation}"
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_core-1.0.0.pre3 app/models/spree/option_value.rb
solidus_core-1.0.0.pre2 app/models/spree/option_value.rb
solidus_core-1.0.0.pre app/models/spree/option_value.rb