On Sun, 16 Jan 2005 19:11:58 -0600, Kevin Pratt
<netikular-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> I ran in to an interesting problem tonight.
>
> If I call find_all on a collection it will start to produce an sql
> statement for each call as expected but it will append the conditions
> to each subsequent call.
>
> Example :
> This code:
> @params[''cb''].each do
> |name,value|
> if (value =="delete")
>
topic=@group.topics.find_first("topic_name=''#{name}''")
> topic.destroy unless topic == nil
> end
> end
>
> when
> @params[''cb''] >
{"Assignments"=>"delete","Exams"=>"delete","Notes"=>"delete","Study
> Group"=>"delete"}
>
> Produces the following sql statements.
> Topic Load (0.003502) SELECT * FROM topics WHERE group_id = 44 AND
> topic_name=''Study Group'' ORDER BY topic_name LIMIT 1
> Topic Load (0.002191) SELECT * FROM topics WHERE group_id = 44 AND
> topic_name=''Study Group'' AND
topic_name=''Notes'' ORDER BY topic_name
> LIMIT 1
> Topic Load (0.002532) SELECT * FROM topics WHERE group_id = 44 AND
> topic_name=''Study Group'' AND
topic_name=''Notes'' AND topic_name=''Exams''
> ORDER BY topic_name LIMIT 1
> Topic Load (0.002801) SELECT * FROM topics WHERE group_id = 44 AND
> topic_name=''Study Group'' AND
topic_name=''Notes'' AND topic_name=''Exams''
> AND topic_name=''Assignments'' ORDER BY topic_name LIMIT 1
>
> If I use the class method Topic.find_all it works as expected it is
> only when I use the instance method find_all does this strange sql
> happen.
>
> Thanks for any input you may have.
> kevin
I don''t see you use find_all()... ?