質問編集履歴

1

コードの追加

2020/08/03 09:24

投稿

wattyo
wattyo

スコア10

test CHANGED
File without changes
test CHANGED
@@ -36,6 +36,106 @@
36
36
 
37
37
 
38
38
 
39
+ list.rb
40
+
41
+ ```ruby
42
+
43
+ class List < ApplicationRecord
44
+
45
+ belongs_to :user
46
+
47
+ has_many :tasks, dependent: :destroy
48
+
49
+
50
+
51
+ validates :title, presence: :true
52
+
53
+ end
54
+
55
+
56
+
57
+ ```
58
+
59
+ task.rb
60
+
61
+ ```ruby
62
+
63
+ class Task < ApplicationRecord
64
+
65
+ belongs_to :list
66
+
67
+ belongs_to :user
68
+
69
+
70
+
71
+ validates :title, presence: :true
72
+
73
+ validates :memo, presence: :true
74
+
75
+ end
76
+
77
+ ```
78
+
79
+
80
+
81
+ マイグレーションファイル
82
+
83
+ ```ruby
84
+
85
+ class CreateLists < ActiveRecord::Migration[6.0]
86
+
87
+ def change
88
+
89
+ create_table :lists do |t|
90
+
91
+ t.text :title, null: false
92
+
93
+ t.references :user, foreign_key: true
94
+
95
+ t.timestamps
96
+
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ ```
104
+
105
+ マイグレーションファイル
106
+
107
+ ```ruby
108
+
109
+ class CreateTasks < ActiveRecord::Migration[6.0]
110
+
111
+ def change
112
+
113
+ create_table :tasks do |t|
114
+
115
+ t.string :title, null: false
116
+
117
+ t.text :memo, null: false
118
+
119
+ t.time :time
120
+
121
+ t.references :user, foreign_key: true
122
+
123
+ t.references :list, foreign_key: true
124
+
125
+ t.timestamps
126
+
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+
134
+
135
+ ```
136
+
137
+
138
+
39
139
  ### 試したこと
40
140
 
41
141