質問編集履歴

1

モデル修正

2020/05/15 11:20

投稿

ai_0928
ai_0928

スコア0

test CHANGED
@@ -1 +1 @@
1
- RubyonRailsでaccepts_nested_attributes_forとcollection_check_boxesを使った登録
1
+ RubyonRailsでaccepts_nested_attributes_forを使った登録
test CHANGED
@@ -40,6 +40,8 @@
40
40
 
41
41
  has_many :t_eigyo_types, class_name: "TEigyoType", dependent: :destroy
42
42
 
43
+ has_many :m_eigyo_types, class_name: "MEigyoType", through: :t_eigyo_types
44
+
43
45
  accepts_nested_attributes_for :t_eigyo_types
44
46
 
45
47
  end
@@ -54,7 +56,9 @@
54
56
 
55
57
  class TEigyoType < ApplicationRecord
56
58
 
57
- belongs_to :store_content, class_name: "TStoreContent", foreign_key: "t_store_content_id"
59
+ belongs_to :store_content, class_name: "TStoreContent", foreign_key: "t_store_content_id" , optional: true
60
+
61
+ belongs_to :m_eigyo_type, class_name: "MEigyoType", foreign_key: :eigyo_type_id, optional: true
58
62
 
59
63
  end
60
64
 
@@ -68,6 +72,10 @@
68
72
 
69
73
  class MEigyoType < ApplicationRecord
70
74
 
75
+ has_many :t_eigyo_types, class_name: "TEigyoType"
76
+
77
+ has_many :t_store_contents, class_name: "TStoreContent", through: :t_eigyo_types
78
+
71
79
  end
72
80
 
73
81
  ```