mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
22 lines
525 B
Ruby
22 lines
525 B
Ruby
# frozen_string_literal: true
|
|
|
|
class ProducerProperty < ApplicationRecord
|
|
self.belongs_to_required_by_default = false
|
|
|
|
belongs_to :producer, class_name: 'Enterprise', touch: true
|
|
belongs_to :property, class_name: 'Spree::Property'
|
|
|
|
default_scope { order("#{table_name}.position") }
|
|
|
|
def property_name
|
|
property&.name
|
|
end
|
|
|
|
def property_name=(name)
|
|
return if name.blank?
|
|
|
|
self.property = Spree::Property.find_by(name:) ||
|
|
Spree::Property.create(name:, presentation: name)
|
|
end
|
|
end
|