Sha256: 27e7b1cfd53518705c0a1eb954bd7cfe99919a906350ebbf96d9fa6de43c286a

Contents?: true

Size: 799 Bytes

Versions: 20

Compression:

Stored size: 799 Bytes

Contents

module Spree
  class ProductProperty < Spree::Base
    belongs_to :product, touch: true, class_name: 'Spree::Product', inverse_of: :product_properties
    belongs_to :property, class_name: 'Spree::Property', inverse_of: :product_properties

    validates :property, presence: true

    validates_with Spree::Validations::DbMaximumLengthValidator, field: :value

    default_scope -> { order("#{self.table_name}.position") }

    # virtual attributes for use with AJAX completion stuff
    def property_name
      property.name if property
    end

    def property_name=(name)
      unless name.blank?
        unless property = Property.find_by(name: name)
          property = Property.create(name: name, presentation: name)
        end
        self.property = property
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
spree_core-2.3.12 app/models/spree/product_property.rb
spree_core-2.3.11 app/models/spree/product_property.rb
spree_core-2.3.10 app/models/spree/product_property.rb
spree_core-2.4.6 app/models/spree/product_property.rb
spree_core-2.3.9 app/models/spree/product_property.rb
spree_core-2.3.8 app/models/spree/product_property.rb
spree_core-2.4.5 app/models/spree/product_property.rb
spree_core-2.4.4 app/models/spree/product_property.rb
spree_core-2.3.7 app/models/spree/product_property.rb
spree_core-2.4.3 app/models/spree/product_property.rb
spree_core-2.4.2 app/models/spree/product_property.rb
spree_core-2.3.6 app/models/spree/product_property.rb
spree_core-2.4.1 app/models/spree/product_property.rb
spree_core-2.4.0 app/models/spree/product_property.rb
spree_core-2.3.5 app/models/spree/product_property.rb
spree_core-2.4.0.rc3 app/models/spree/product_property.rb
spree_core-2.4.0.rc2 app/models/spree/product_property.rb
spree_core-2.4.0.rc1 app/models/spree/product_property.rb
spree_core-2.3.4 app/models/spree/product_property.rb
spree_core-2.3.3 app/models/spree/product_property.rb