1
考慮以下幾點:鑑於以下用戶<>項目<>權限<>角色模型,如何獲取項目的團隊成員?
class User < AR::B
has_many :permissions
has_many :projects, :through => :permissions
end
class Project < AR::B
has_many :permissions
has_many :users, :through => :permissions
end
class Role < AR::B
has_many :permissions
end
class Permission < AR::B
belongs_to :user
belongs_to :project
belongs_to :role
end
我感興趣的項目模型(project.rb)返回該項目的所有成員(bassed在權限表<>用戶&角色表創建範圍
所需的輸出: user.name,role.name
這裏是我的範圍在模型中,這是不返回所需的 輸出:
class Project < ActiveRecord::Base
has_many :permissions
has_many :users, :through => :permissions
#Playing with Scopes
scope :teammembers,
Project.permissions.joins(:users, :roles)
end
試圖找出如何使用ActiveRecord獲取輸出。由於