I have three models:
class User < ActiveRecord::Base
has_many :projects, :through => :permissions
class Permission < ActiveRecord::Base
belongs_to :user
belongs_to :project
belongs_to :role
class Project < ActiveRecord::Base
has_many :users, :through => :permissions
It is very simple, taking into account the above, to get all users of the project: @project.users
But what I want to do is get something like this: Get all users in all user projects.
So, if a user has 3 projects, each of which has 5 users. I want to complete a query to get all 15 users in all user groups.
I am trying with this.
current_user.projects.users
but Rails doesn't really like it. current_user.projects works fine, but not users.
Suggestions? Ideas? thank!
UPDATED CODE 3 based on noodl comments
scope :suggestedContacts, lambda { |user|
users_from_projects = user.projects.reduce([]) {|all_users,prj|
all_users + prj.users
}.uniq
}
ERRORS:
NoMethodError (undefined `includes_values' method for #):
source
share