質問編集履歴
1
マイグレーションファイルの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -123,3 +123,65 @@
|
|
123
123
|
今はこのようにコードを書いています。
|
124
124
|
|
125
125
|
他に必要なコードがあれば記載しますので、ご教授よろしくお願いします。
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
###補足・追記
|
130
|
+
|
131
|
+
`Messagesテーブルのマイグレーションファイル`
|
132
|
+
|
133
|
+
```
|
134
|
+
|
135
|
+
class CreateMessages < ActiveRecord::Migration
|
136
|
+
|
137
|
+
def change
|
138
|
+
|
139
|
+
create_table :messages do |t|
|
140
|
+
|
141
|
+
t.text :body
|
142
|
+
|
143
|
+
t.references :conversation, index: true, foreign_key: true
|
144
|
+
|
145
|
+
t.references :user, index: true, foreign_key: true
|
146
|
+
|
147
|
+
t.boolean :read, default: false
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
t.timestamps null: false
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
`Conversationsテーブルのマイグレーションファイル`
|
164
|
+
|
165
|
+
```
|
166
|
+
|
167
|
+
class CreateConversations < ActiveRecord::Migration
|
168
|
+
|
169
|
+
def change
|
170
|
+
|
171
|
+
create_table :conversations do |t|
|
172
|
+
|
173
|
+
t.integer :sender_id
|
174
|
+
|
175
|
+
t.integer :recipient_id
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
t.timestamps null: false
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
```
|