From 215f2897f3b08649d32a9ae2f08338c6fbd7ee10 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 8 Nov 2019 17:48:49 +0000 Subject: [PATCH] Bring Property model from spree core --- app/models/spree/property.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 app/models/spree/property.rb diff --git a/app/models/spree/property.rb b/app/models/spree/property.rb new file mode 100644 index 0000000000..29bf3b33fc --- /dev/null +++ b/app/models/spree/property.rb @@ -0,0 +1,21 @@ +module Spree + class Property < ActiveRecord::Base + has_and_belongs_to_many :prototypes, join_table: 'spree_properties_prototypes' + + has_many :product_properties, dependent: :destroy + has_many :products, through: :product_properties + + attr_accessible :name, :presentation + + validates :name, :presentation, presence: true + + scope :sorted, -> { order(:name) } + + 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 + end +end