Weird active record problem - goes away with cache_classes change

I have three active record objects, User, Question and Answer

  • Questions belong to a user and has_many answers
  • Answer belongs to a user

Now, when I start with an array of answers, I can do this
successfully:

for a in answers
a.user.user_id
end

If I do this:

for q in questions
answers = q.answers
for a in answers
a.user.user_id
end
end

It works the first time, but it fails the 2nd time on with this:

ActionView::TemplateError (undefined method `user’ for #<Answer:
0x351617c>) on line #45 of app/views/lib/_qnalist.rhtml:
42:


43: <%= format_line_wrap(a.body, width, 14) %></
span>

44:
45:
Answered by <%= a.user.user_id %> - <%= a.created_at %>
46:
47:

48:
&nbsp

However, this is fixed IF I change development.rb and change
cache_classes to true

config.cache_classes = true

I have no clue what is happening :(.

Any one knows how to fix this?