mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Bring Property model from spree core
This commit is contained in:
21
app/models/spree/property.rb
Normal file
21
app/models/spree/property.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user