Skip to content

Commit dd9bb7a

Browse files
committed
Classifications: Add foreign keys
This join table needs both references to be pointing to valid records. A uniqueness index for the taxon id in this table is already present.
1 parent 62c8723 commit dd9bb7a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

core/app/models/spree/classification.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module Spree
44
class Classification < Spree::Base
55
self.table_name = 'spree_products_taxons'
66
acts_as_list scope: :taxon
7-
belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications, touch: true, optional: true
8-
belongs_to :taxon, class_name: "Spree::Taxon", inverse_of: :classifications, touch: true, optional: true
7+
belongs_to :product, class_name: "Spree::Product", inverse_of: :classifications, touch: true
8+
belongs_to :taxon, class_name: "Spree::Taxon", inverse_of: :classifications, touch: true
99

1010
# For https://github.com/spree/spree/issues/3494
1111
validates :taxon_id, uniqueness: { scope: :product_id, message: :already_linked }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class AddFkToClassifications < ActiveRecord::Migration[7.0]
4+
def change
5+
add_foreign_key :spree_products_taxons, :spree_products, column: :product_id
6+
add_foreign_key :spree_products_taxons, :spree_taxons, column: :taxon_id
7+
end
8+
end

0 commit comments

Comments
 (0)