我有以下型号:
class Board < ActiveRecord::Base
has_many :users, :through => :participants do
def manager
where("participants.role = ?", "Manager").first
end
end
这允许我在我的控制器和视图中执行以下操作
@board.users.manager
有没有办法使用named_scope来获取电路板的管理器,如下所示:
@board.manager
答案 0 :(得分:2)
以下是一个示例解决方案:
class Board < ActiveRecord::Base
has_many :users, :through => :participants do
def manager
where("participants.role = ?", "Manager").first
end
end
delegate :manager, :to => :users
end