Hello all! I've got the following models:
project.rb
has_many :tasks
task.rb
belongs_to :project
has_many :assignments
has_many :users, :through => :assignments
user.rb
has_many :assignments
has_many :tasks, :through => :assignments
assignment.rb
belongs_to :task
belongs_to :user
So for example: Project.first.title #=> "Manhattan" Project.first.tasks.map(&:name) # => ['Find Scientists', 'Find Money', 'Find Location'] Project.first.tasks.first.users.map(&:full_name) #=> ['James Maxwell', 'Evariste Galois', 'Jules Verne']
My first question is: How can I find all the persons' names possibly with symbol to proc in one shot, I tried:
Project.first.tasks.users.full_name #=> AND FAILED
Project.first.tasks.map(&:users).full_name #=> AND FAILED
Project.first.tasks.map(&:users).map(&:full_name) #=> AND FAILED
Any ideas?
And I think this following question might be in the same ball park:
How can I do a find of Project with conditions that search the 'full_name' attribute of the users its tasks?
Example
Project.all(:include => {:tasks => :users}, :conditions => ['tasks.users.full_name LIKE ?', query]) #this failed
I think the problem is at the 'tasks.users'.
Thanks everyone, have a happy thanksgiving!