Odd Join

@user.task_assignments is a list of tasks, so you can't do
@user.task_assignments.task.name - how should the interpreter know
which task assignment (out of many) you want the task for?

You'll have to iterate through the tasks in some way, for example to
collect all the names:

names = @user.task_assignments.collect { |assignment| assignment.task.name }

or

<% for assignment in @user.task_assignments %>
  <%= assignment.task.name %>
  <%= assignment.to.name %>
<% end %>

You can also save yourself some typing by declaring

class User
  has_many :tasks, :through=>task_assignments
end

Read up on "has_many through", that should give you some ideas.

Cheers,
Max

class User < ActiveRecord::Base
   has_many :task_assignments, :foreign_key => 'to_user_id'
   has_many :tasks, :through => :task_assignments
   has_many :delegated_assignments, :class_name => 'TaskAssignments', :foreign_key => 'from_user_id'
   has_many :delegated_tasks, :through => :delegated_assignments
end

class Task < ActiveRecord::Base
end

class TaskAssignments < ActiveRecord::Base
   belongs_to :task
   belongs_to :from_user, :class_name => 'User', :foreign_key => 'from_user_id'
   belongs_to :to_user, :class_name => 'User', :foreign_key => 'to_user_id'
end

puts "Tasks for #{@user.name}:"
for assignment in @user.tasks
   puts " #{assignment.task.name} from #{assignment.from_user.name}"
end

This may not be exactly how you're setup works, but I think it's accurate. Please let us know how it goes.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com