【发布时间】:2013-11-21 19:08:36
【问题描述】:
我有两个模型
class Endorsement < ActiveRecord::Base
belongs_to :user, foreign_key: "endorser_id"
belongs_to :user, foreign_key: "endorsee_id"
end
class User < ActiveRecord::Base
# Contains a name attribute
has_many :endorsements, foreign_key: "endorser_id"
has_many :endorsements, foreign_key: "endorsee_id"
end
我想得到背书人的名字。当我做endorsement.user.name 时,我收到endorsee_id 的名字,而我真的想要endorser_id 的名字。我将如何在 Rails 中执行此操作?
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-4 associations