# Has\_many through, model lost their methods after second load

**URL:** <https://www.ruby-forum.com/t/has-many-through-model-lost-their-methods-after-second-load/113365>\
**Category:** Rails\
**Created:** [August 30, 2007, 11:50am UTC](https://www.ruby-forum.com/t/has-many-through-model-lost-their-methods-after-second-load/113365 "2007-08-30T11:50:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![benni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@benni](https://www.ruby-forum.com/u/benni)\
**Post date:** [August 30, 2007, 11:50am UTC](https://www.ruby-forum.com/t/has-many-through-model-lost-their-methods-after-second-load/113365/1 "2007-08-30T11:50:06Z")

</div>

hello

I’m using the has\_many through association, because i want additional  
attributes in the assignment-table. my association looks like this:

class Task \< ActiveRecord::Base  
has\_many :assignments, :dependent =\> :destroy  
has\_many :users, :through =\> :assignments

…

class Assignment \< ActiveRecord::Base  
belongs\_to :user  
belongs\_to :task  
end

class User \< ActiveRecord::Base  
has\_many :assignments, :dependent =\> :destroy  
has\_many :tasks, :through =\> :assignments

…

my Assignment-Model has also the attribut “accepted”. When I search for  
unaccepted Tasks for a certain user I use the class-method:

class User …  
def unaccepted\_tasks  
self.tasks.find :all, :conditions =\> [“accepted = ?”, false], :order  
=\> “due\_date DESC”  
end

Ok. that works. but when I now try loop over the tasks and use its own  
method users (task.users…), i get an error.

my controller:  
def myTasks  
@tasks = @current\_user.unaccepted\_tasks  
end

my view:  
\<%for task in @tasks %\>

  
  
\<%= link\_to task.name, :controller =\> “tasks”, :action =\>  
“show”, :id =\> task %\>  
  
  
\<% unless task.users.empty?  
owner = Array.new  
task.assignments.each do |ass|  
if ass.accepted?  
nick = “#{ass.user.nick.to\_s}”  
else  
nick = “#{ass.user.nick.to\_s}”  
end  
owner \<\< nick  
end %\>  
\<%= owner.join(", ")%\>  
\<% end %\>  
  
\<% end %\>

the error:  
undefined method `users’ for #Task:0xb69dc964

funny information. the first time I load the action myTaks works. but  
the second (and later) request fails.

Any ideas?

greetings  
benni
