From: Jan Svitok Date: 2006-07-24T18:55:26+09:00 Subject: Re: Bad query? Try to fiddle with the condition... what are your course numbers like? J. On 7/24/06, raffir@gmail.com wrote: > I have a find() query inside a for loop. Basically, I want the loop to > go through all elements in User.accounts and find all elements in > Accounts that have the same name as each element (to see other users > who have accounts with the same name). > > Right now my code is as follows: > > > <%@session['user'].accounts.each do |i| %> > <%Accounts.find(:all, :conditions => ["coursenumber LIKE ?", > "%#{i.coursenumber}%"]).each do |account| %> > > > > > > > > > > <%end%> > <% end %> >
<%= account.coursename %><%= account.coursenumber %><%= account.user_id%><%= account.first_name%> <%= account.last_name%><%= link_to 'Show', :controller=>'user', :action=>'userdetails', > :id=> account.user_id %>
> > This has the effect of outputting every single account in the Accounts > table. I'd like to restrict it to just outputting those accounts with > the same course name/number as each one of the User's. > > > Thanks a lot, > > - Raffi. > > >