Sha256: 36b6d9be71399b2fcb133440ee338e35e4ec97b40a104ff12a9b22fb86eff324

Contents?: true

Size: 713 Bytes

Versions: 9

Compression:

Stored size: 713 Bytes

Contents

module Spree
  class Property < ActiveRecord::Base
    has_and_belongs_to_many :prototypes, join_table: 'spree_properties_prototypes'

    has_many :product_properties, dependent: :delete_all
    has_many :products, through: :product_properties

    validates :name, :presentation, presence: true

    scope :sorted, -> { order(:name) }

    after_touch :touch_all_products

    def self.find_all_by_prototype(prototype)
      id = prototype
      id = prototype.id if prototype.class == Prototype
      joins("LEFT JOIN properties_prototypes ON property_id = #{self.table_name}.id").
        where(prototype_id: id)
    end

    private

    def touch_all_products
      products.each(&:touch)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_core-2.1.12 app/models/spree/property.rb
spree_core-2.1.11 app/models/spree/property.rb
spree_core-2.1.10 app/models/spree/property.rb
spree_core-2.1.9 app/models/spree/property.rb
spree_core-2.1.8 app/models/spree/property.rb
spree_core-2.1.7 app/models/spree/property.rb
spree_core-2.1.6 app/models/spree/property.rb
spree_core-2.1.5 app/models/spree/property.rb
spree_core-2.1.4 app/models/spree/property.rb