Sha256: af6426a1016cb8999d46af8e90fd06eabd325880c6685dafbf45daa99286e09f

Contents?: true

Size: 752 Bytes

Versions: 2

Compression:

Stored size: 752 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

    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.update_all(updated_at: Time.current)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_core-2.4.0.rc2 app/models/spree/property.rb
spree_core-2.4.0.rc1 app/models/spree/property.rb