我有一个模型用户。用户可以拥有一个对象。用户还可以相互发送对象。我正在尝试访问用户的所有“发件人”,以便我可以访问 @user.senders 并获取该用户的所有唯一发件人。这是我的设置:
class Object < ActiveRecord::Base
belongs_to :user
has_many :senders, through: :object_relationships, source: :user, class_name: "User"
has_many :object_relationships
end
class User < ActiveRecord::Base
has_many :owned_objects, inverse_of: :user
has_many :objects, through: :object_relationships
has_many :object_relationships
end
class ObjectRelationship < ActiveRecord::Base
belongs_to :user
belongs_to :object
end
有任何想法吗?