Sha256: 341a4198c4cac1f4c3a7677c0899d258060913a1bc66cab7d15a1c17327d62a4

Contents?: true

Size: 793 Bytes

Versions: 1

Compression:

Stored size: 793 Bytes

Contents

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

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

    validates :name, :presentation, presence: true

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

    after_touch :touch_all_products

    self.whitelisted_ransackable_attributes = ['presentation']

    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

1 entries across 1 versions & 1 rubygems

Version Path
spree_core-2.3.13 app/models/spree/property.rb