質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -76,6 +76,40 @@
|
|
76
76
|
|
77
77
|
```
|
78
78
|
|
79
|
+
モデルの関連定義
|
80
|
+
|
81
|
+
```model
|
82
|
+
|
83
|
+
class User < ApplicationRecord
|
84
|
+
|
85
|
+
has_many :active_friendships, class_name:"Friendship", foreign_key: "follower_id", dependent: :destroy
|
86
|
+
|
87
|
+
has_many :passive_friendships, class_name:"Friendship", foreign_key: "followed_id", dependent: :destroy
|
88
|
+
|
89
|
+
has_many :following, through: :active_friendships, source: :followed
|
90
|
+
|
91
|
+
has_many :followers, through: :passive_friendships, source: :follower
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
```model
|
96
|
+
|
97
|
+
class Friendship < ApplicationRecord
|
98
|
+
|
99
|
+
validates :follower_id, presence: true
|
100
|
+
|
101
|
+
validates :followed_id, presence: true
|
102
|
+
|
103
|
+
belongs_to :follower, class_name: "User"
|
104
|
+
|
105
|
+
belongs_to :followed, class_name: "User"
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
79
113
|
###試している処理
|
80
114
|
|
81
115
|
現在、以下の処理で自分がフォローしている全てのユーザーをフォローから外す処理ができました。
|