質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -37,6 +37,23 @@
|
|
37
37
|
t.index ["follower_id"], name: "index_friendships_on_follower_id"
|
38
38
|
end
|
39
39
|
```
|
40
|
+
モデルの関連定義
|
41
|
+
```model
|
42
|
+
class User < ApplicationRecord
|
43
|
+
has_many :active_friendships, class_name:"Friendship", foreign_key: "follower_id", dependent: :destroy
|
44
|
+
has_many :passive_friendships, class_name:"Friendship", foreign_key: "followed_id", dependent: :destroy
|
45
|
+
has_many :following, through: :active_friendships, source: :followed
|
46
|
+
has_many :followers, through: :passive_friendships, source: :follower
|
47
|
+
```
|
48
|
+
```model
|
49
|
+
class Friendship < ApplicationRecord
|
50
|
+
validates :follower_id, presence: true
|
51
|
+
validates :followed_id, presence: true
|
52
|
+
belongs_to :follower, class_name: "User"
|
53
|
+
belongs_to :followed, class_name: "User"
|
54
|
+
end
|
55
|
+
|
56
|
+
```
|
40
57
|
###試している処理
|
41
58
|
現在、以下の処理で自分がフォローしている全てのユーザーをフォローから外す処理ができました。
|
42
59
|
しかし、自分のことをフォローしているユーザーをフォローから外す処理ができずにいます。
|