https://www.railstutorial.org/book/following_users으로 작동합니다 :
class User < ApplicationRecord
has_many :microposts, dependent: :destroy
has_many :active_relationships, class_name: "Relationship",
foreign_key: "follower_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
.
.
.
end
그래서, 당신이 아래에 같이 할 수 있다고 생각 문제를 해결하십시오 :
class User < ApplicationRecord
has_many :microposts, dependent: :destroy
has_many :active_relationships, ->{ where(status: true) },
class_name: "Relationship",
foreign_key: "follower_id",
dependent: :destroy
has_many :following, through: :active_relationships, source: :followed
.
.
.
end
희망이 있습니다.
여전히 상태가 true 및 false 인 current_user의 모든 관계를 반환합니다 .. – User101
그것은 내 것이고 .. 지금은 감사하고 있습니다 ... – User101
안녕하세요. – hoangdd