質問編集履歴
1
各モデルのリレーションを追記しました!
test
CHANGED
File without changes
|
test
CHANGED
@@ -150,6 +150,72 @@
|
|
150
150
|
|
151
151
|
|
152
152
|
|
153
|
-
|
154
|
-
|
155
|
-
```
|
153
|
+
```
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
group.rb↓
|
158
|
+
|
159
|
+
```
|
160
|
+
|
161
|
+
class Group < ApplicationRecord
|
162
|
+
|
163
|
+
has_many :group_users
|
164
|
+
|
165
|
+
has_many :users, through: :group_users
|
166
|
+
|
167
|
+
has_many :messages
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
message.rb↓
|
176
|
+
|
177
|
+
```
|
178
|
+
|
179
|
+
class Message < ApplicationRecord
|
180
|
+
|
181
|
+
belongs_to :user
|
182
|
+
|
183
|
+
belongs_to :group
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
user.rb↓
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
class User < ApplicationRecord
|
196
|
+
|
197
|
+
has_many :group_users
|
198
|
+
|
199
|
+
has_many :messages
|
200
|
+
|
201
|
+
has_many :groups, through: :group_users
|
202
|
+
|
203
|
+
end
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
group_user.rb↓
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
class GroupUser < ApplicationRecord
|
214
|
+
|
215
|
+
belongs_to :group
|
216
|
+
|
217
|
+
belongs_to :user
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
```
|