Reputation: 7866
I have the following model:
class Board < ActiveRecord::Base
has_many :users, :through => :participants do
def manager
where("participants.role = ?", "Manager").first
end
end
This allows me to do the following in my controller and views
@board.users.manager
Is there a way to use a named_scope to be able to get the manager for a board as follows:
@board.manager
Upvotes: 1
Views: 73
Reputation: 40333
Here's a sample solution:
class Board < ActiveRecord::Base
has_many :users, :through => :participants do
def manager
where("participants.role = ?", "Manager").first
end
end
delegate :manager, :to => :users
end
Upvotes: 2