mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Rails 5 introduced this new class to confine application-specific monkey patches to our models only, and not leak into other libraries using ActiveRecord::Base. https://bigbinary.com/blog/application-record-in-rails-5
22 lines
645 B
Ruby
22 lines
645 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Spree
|
|
class Classification < ApplicationRecord
|
|
self.table_name = 'spree_products_taxons'
|
|
belongs_to :product, class_name: "Spree::Product", touch: true
|
|
belongs_to :taxon, class_name: "Spree::Taxon", touch: true
|
|
|
|
before_destroy :dont_destroy_if_primary_taxon
|
|
|
|
private
|
|
|
|
def dont_destroy_if_primary_taxon
|
|
return unless product.primary_taxon == taxon
|
|
|
|
errors.add :base, I18n.t(:spree_classification_primary_taxon_error, taxon: taxon.name,
|
|
product: product.name)
|
|
throw :abort
|
|
end
|
|
end
|
|
end
|