Sha256: 56e07ea4755999d06657dfbc6363d6421e30aab6a067b2efc39ddf32f3220944

Contents?: true

Size: 805 Bytes

Versions: 48

Compression:

Stored size: 805 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_value_variants, class_name: 'Spree::OptionValueVariant'
    has_many :variants, through: :option_value_variants, class_name: 'Spree::Variant'

    with_options presence: true do
      validates :name, uniqueness: { scope: :option_type_id, case_sensitive: false }
      validates :presentation
    end

    after_touch :touch_all_variants

    delegate :name, :presentation, to: :option_type, prefix: true, allow_nil: true

    self.whitelisted_ransackable_attributes = ['presentation']

    private

    def touch_all_variants
      variants.update_all(updated_at: Time.current)
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/models/spree/option_value.rb
spree_core-4.1.15 app/models/spree/option_value.rb
spree_core-4.2.7 app/models/spree/option_value.rb
spree_core-4.2.6 app/models/spree/option_value.rb
spree_core-4.2.5 app/models/spree/option_value.rb
spree_core-4.1.14 app/models/spree/option_value.rb
spree_core-4.0.8 app/models/spree/option_value.rb
spree_core-4.2.4 app/models/spree/option_value.rb
spree_core-4.2.3.1 app/models/spree/option_value.rb
spree_core-4.1.13.1 app/models/spree/option_value.rb
spree_core-4.0.7.1 app/models/spree/option_value.rb
spree_core-4.2.3 app/models/spree/option_value.rb
spree_core-4.2.2 app/models/spree/option_value.rb
spree_core-4.2.1 app/models/spree/option_value.rb
spree_core-4.0.7 app/models/spree/option_value.rb
spree_core-4.2.0 app/models/spree/option_value.rb
spree_core-4.2.0.rc5 app/models/spree/option_value.rb
spree_core-4.2.0.rc4 app/models/spree/option_value.rb
spree_core-4.2.0.rc3 app/models/spree/option_value.rb
spree_core-4.1.13 app/models/spree/option_value.rb