From: Robert Dober Date: 2006-07-24T17:40:53+09:00 Subject: Re: Bad query? ------=_Part_7713_7100037.1153730448567 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 =3D> ["coursenumber LIKE ?", > "%#{i.coursenumber}%"]).each do |account| %> > > > > > > > > > > <%end%> > <% end %> >
<%=3D account.coursename %><%=3D account.coursenumber %><%=3D account.user_id%><%=3D account.first_name%> <%=3D > account.last_name%><%=3D link_to 'Show', :controller=3D>'user', > :action=3D>'userdetails', > :id=3D> 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. Hmm, looks like a Rails problem, although there are a lot of nice people around who might be willing to help, sorry I cannot :(, I think you should post to the Rails Mailing List. http://www.rubyonrails.org/community Cheers Robert --=20 Deux choses sont infinies : l'univers et la b=EAtise humaine ; en ce qui concerne l'univers, je n'en ai pas acquis la certitude absolue. - Albert Einstein ------=_Part_7713_7100037.1153730448567--