我有以下型号:
class Publication < ActiveRecord::Base
has_many :reviews
has_many :users, :through => :owned_publications
has_many :owned_publications
end
class User < ActiveRecord::Base
has_many :publications, :through => :owned_publications
has_many :owned_publications
end
class OwnedPublication < ActiveRecord::Base
belongs_to :publication
belongs_to :user
has_one :review, :conditions => "user_id = #{self.user.id} AND publication_id = #{self.publication.id}"
end
在第三个模型中,我试图用一对变量设置一个条件。语法似乎有效,只是 self 不是 OwnedPublication 的实例。是否可以获取 OwnedPublication 的当前实例并将其置于条件中?