Pedro Valentini
2005-May-23 21:27 UTC
find_all get a vector or a object. How know what is?
Hi, The method find_all of the active record can get a vector of objects or a object. What recurse you use to know what was returned? I''m using: @anwers = Anwer.find_all for answer as @anwers ... end If the thable have only one record or none happen an error!! To nothing I protect with a nil!=@answers, but how protect from one record???? Thank''s -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Tobias Lutke
2005-May-23 21:30 UTC
Re: find_all get a vector or a object. How know what is?
thats not true. find_all always returns an array. By the way, find_all is deprecated. use .find(:all) instead. If find_all would really return either array or nil you could use the .to_a method which every ruby object supports. On a array it does nothing, on a object it returns an array with the object as only element so or answer as @anwers.to_a ... end will always work On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Hi, > > The method find_all of the active record can get a vector of objects or > a object. > What recurse you use to know what was returned? > I''m using: > @anwers = Anwer.find_all > for answer as @anwers > ... > end > If the thable have only one record or none happen an error!! > To nothing I protect with a nil!=@answers, but how protect from one > record???? > > Thank''s > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Tobi http://www.snowdevil.ca - Snowboards that don''t suck http://typo.leetsoft.com - Open source weblog engine http://blog.leetsoft.com - Technical weblog
Pedro Valentini
2005-May-23 21:50 UTC
Re: find_all get a vector or a object. How know what is?
Thank you, is hard to find tips like .to_a I really was wrong about the "find" .find(:all) here get: Couldn''t find Questions with ID=all I need to update my rubyonrails?? Pedro Tobias Lutke escreveu:>thats not true. find_all always returns an array. > >By the way, find_all is deprecated. use .find(:all) instead. > >If find_all would really return either array or nil you could use the >.to_a method which every ruby object supports. On a array it does >nothing, on a object it returns an array with the object as only >element so > >or answer as @anwers.to_a > ... >end > >will always work > >On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>Hi, >> >>The method find_all of the active record can get a vector of objects or >>a object. >>What recurse you use to know what was returned? >>I''m using: >>@anwers = Anwer.find_all >>for answer as @anwers >> ... >>end >>If the thable have only one record or none happen an error!! >>To nothing I protect with a nil!=@answers, but how protect from one >>record???? >> >>Thank''s >> >>-- >> >>Pedro C. Valentini >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>+55 (21) 8708-8035 >> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Michael Koziarski
2005-May-23 23:22 UTC
Re: find_all get a vector or a object. How know what is?
On 5/24/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Thank you, is hard to find tips like .to_a > I really was wrong about the "find" > > .find(:all) here get: Couldn''t find Questions with ID=all > I need to update my rubyonrails??Yes, the new finder syntax was introduced in 0.12, the upgrade should be seamless.> Pedro > > > > Tobias Lutke escreveu: > > >thats not true. find_all always returns an array. > > > >By the way, find_all is deprecated. use .find(:all) instead. > > > >If find_all would really return either array or nil you could use the > >.to_a method which every ruby object supports. On a array it does > >nothing, on a object it returns an array with the object as only > >element so > > > >or answer as @anwers.to_a > > ... > >end > > > >will always work > > > >On 5/23/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > > > > >>Hi, > >> > >>The method find_all of the active record can get a vector of objects or > >>a object. > >>What recurse you use to know what was returned? > >>I''m using: > >>@anwers = Anwer.find_all > >>for answer as @anwers > >> ... > >>end > >>If the thable have only one record or none happen an error!! > >>To nothing I protect with a nil!=@answers, but how protect from one > >>record???? > >> > >>Thank''s > >> > >>-- > >> > >>Pedro C. Valentini > >>pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > >>+55 (21) 8708-8035 > >> > >>_______________________________________________ > >>Rails mailing list > >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >>http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > >> > > > > > > > > > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz