有很多有多个源param RoR

时间:2017-07-03 18:46:32

标签: ruby-on-rails has-many-through

在我的RoR应用中,用户可以关注乐队和用户

class User < ApplicationRecord
   has_many :active_relationships, class_name: "FollowingRelationship", foreign_key: "follower_id", dependent: :destroy
   has_many :passive_relationships, class_name: "FollowingRelationship", foreign_key: "followable_id", dependent: :destroy


   has_many :followings_bands, through: :active_relationships, source: :followable, source_type: 'Band', dependent: :delete_all
   has_many :followings_users, through: :active_relationships, source: :followable, source_type: 'User', dependent: :delete_all

   has_many :followers, through: :passive_relationships, source: :follower, dependent: :delete_all
 end

所以跟随的实体是用户或乐队,但我找不到检索我的粉丝的方法,分为用户和乐队(以这种方式,输入@ user.followers我检索所有粉丝,两个乐队和用户,但这不是我在寻找

我看起来像是followers_users和followers_band

有什么建议吗?

0 个答案:

没有答案
相关问题