Skip to content

Commit 53d480c

Browse files
committed
ProductOptionType: Add foreign key constraints
This is a join table, both values must be present and pointing to an entry in the correct table.
1 parent 2788350 commit 53d480c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

core/app/models/spree/product_option_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
module Spree
44
class ProductOptionType < Spree::Base
5-
belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types, touch: true, optional: true
6-
belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :product_option_types, optional: true
5+
belongs_to :product, class_name: 'Spree::Product', inverse_of: :product_option_types, touch: true
6+
belongs_to :option_type, class_name: 'Spree::OptionType', inverse_of: :product_option_types
77
acts_as_list scope: :product
88
end
99
end
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 AddFkToProductOptionTypes < ActiveRecord::Migration[7.0]
4+
def change
5+
add_foreign_key :spree_product_option_types, :spree_products, column: :product_id
6+
add_foreign_key :spree_product_option_types, :spree_option_types, column: :option_type_id
7+
end
8+
end

0 commit comments

Comments
 (0)