Profile
モデルを介して接続された自己参照モデルがありRelationship
ます。
class Profile < ActiveRecord::Base
belongs_to :user
has_many :accepted_relationships, class_name: 'Relationship', foreign_key: 'responder_id'
has_many :followers, through: :accepted_relationships, source: 'initiator'
has_many :initiated_relationships, class_name: 'Relationship', foreign_key: 'initiator_id'
has_many :followed_profiles, through: :initiated_relationships, source: 'responder'
has_many :groups
end
class Relationship < ActiveRecord::Base
belongs_to :responder, class_name: 'Profile', foreign_key: 'responder_id'
belongs_to :initiator, class_name: 'Profile', foreign_key: 'initiator_id'
belongs_to :group
end
class Group < ActiveRecord::Base
belongs_to :profile
has_many :relationships
attr_accessible :name
end
問題は、結合モデルのデータにアクセスする方法がわからないことです。私が何かをするなら;
user.profiles[1].followers[1]
必要なプロファイルが表示されます。私も次のようなものが欲しいです。
user.profiles[1].followers[1].assigned_group
その関係が属するグループにアクセスできました。
私のデザインは間違っていますか、それともここで何かを見落としていますか?