Hugo Magalhaes
2005-Aug-15 19:34 UTC
Find beginner question (using a find with many conditions)
Hello all. I want to do a query to search for some documents that have a certain document.type and document.area. I''m using the find method do do that but it always gives the same error "wrong number of bind variables (3 for 1) in: type=(?)". Here is the code: Can anyone help me? def view_all conditions = Array.new conditions.push("type=(?)") conditions.push("word") conditions.push("area=(?)") conditions.push("sports") documents= Document.find(:all, :conditions => conditions) render_text documents.inspect end Thanks in advance, Hugo
Steve Downey
2005-Aug-15 19:41 UTC
Re: Find beginner question (using a find with many conditions)
Hugo Magalhaes wrote:>Hello all. > >I want to do a query to search for some documents that have a certain >document.type and document.area. I''m using the find method do do that >but it always gives the same error "wrong number of bind variables (3 >for 1) in: type=(?)". > >Here is the code: > >Can anyone help me? >def view_all > conditions = Array.new > conditions.push("type=(?)") > conditions.push("word") > conditions.push("area=(?)") > conditions.push("sports") > documents= Document.find(:all, :conditions => conditions) > render_text documents.inspect > end > > >def view_all documents= Document.find(:all, :conditions => [''type = ? and area = ?, "word", "sports"]) render_text documents.inspect end
Hugo Magalhaes
2005-Aug-15 20:12 UTC
Re: Find beginner question (using a find with many conditions)
Thanks Steve. That resolved the problem! On 8/15/05, Steve Downey <sldowney-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:> Hugo Magalhaes wrote: > > >Hello all. > > > >I want to do a query to search for some documents that have a certain > >document.type and document.area. I''m using the find method do do that > >but it always gives the same error "wrong number of bind variables (3 > >for 1) in: type=(?)". > > > >Here is the code: > > > >Can anyone help me? > >def view_all > > conditions = Array.new > > conditions.push("type=(?)") > > conditions.push("word") > > conditions.push("area=(?)") > > conditions.push("sports") > > documents= Document.find(:all, :conditions => conditions) > > render_text documents.inspect > > end > > > > > > > > def view_all > documents= Document.find(:all, > :conditions => [''type = ? and area = ?, "word", "sports"]) > render_text documents.inspect > end > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >