hi.. how can I retrive data from a specific row of table by giving two or more properties of that row? examlpe I want to get data which ID = 23 and NAME = "xx" like thankx --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
xxmithila wrote:> hi.. > > how can I retrive data from a specific row of table by giving two > or more properties of that row? > examlpe I want to get data which ID = 23 and NAME = "xx" likeAs long as your table is made up of Models, you can do something like: @mydata = ModelName.find(''23'', :conditions => "NAME = ''xxx''" ) HTH Matt --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, xxmithila wrote:> how can I retrive data from a specific row of table > by giving two or more properties of that row? > examlpe I want to get data which > ID = 23 and NAME = "xx" likeIf you know the ID, you don''t need anything else. IDs are unique so the query on the second field just eats cycles with no upside. Assuming this was just a poorly thought-out example... two or more properties are queried, in the most general case, with: Model.find(all, :conditions => ["first_condition =? && second_condition ?", first_param, second_param]) Use the find_by helpers for more readable / idiomatic code. HTH, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Oct 31, 2008 at 8:42 AM, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org>wrote:> > Hi, > > xxmithila wrote: > > > how can I retrive data from a specific row of table > > by giving two or more properties of that row? > > examlpe I want to get data which > > ID = 23 and NAME = "xx" like > > If you know the ID, you don''t need anything else. IDs are unique so the > query on the second field just eats cycles with no upside. Assuming this > was just a poorly thought-out example... > > two or more properties are queried, in the most general case, with: > Model.find(all, :conditions => ["first_condition =? && second_condition > ?", first_param, second_param]) > > Use the find_by helpers for more readable / idiomatic code. > > HTH, > Bill > > > hoooo >@mydata = ModelName.find(''23'', :conditions => "NAME = ''xxx''" ) but this command return error " You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each " I know that code is correct but it return error. What is the reson for this? xxmithila --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sat, Nov 1, 2008 at 6:36 AM, mithila karunarathna <xxmithilaxx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > > On Fri, Oct 31, 2008 at 8:42 AM, Bill Walton <bill.walton-xwVYE8SWAR3R7s880joybQ@public.gmane.org>wrote: > >> >> Hi, >> >> xxmithila wrote: >> >> > how can I retrive data from a specific row of table >> > by giving two or more properties of that row? >> > examlpe I want to get data which >> > ID = 23 and NAME = "xx" like >> >> If you know the ID, you don''t need anything else. IDs are unique so the >> query on the second field just eats cycles with no upside. Assuming this >> was just a poorly thought-out example... >> >> two or more properties are queried, in the most general case, with: >> Model.find(all, :conditions => ["first_condition =? && second_condition >> ?", first_param, second_param]) >> >> Use the find_by helpers for more readable / idiomatic code. >> >> HTH, >> Bill >> >> >> hoooo >> > @mydata = ModelName.find(''23'', :conditions => "NAME = ''xxx''" ) > but this command return error > " > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > " > I know that code is correct but it return error. What is the reson for > this? > xxmithila > > >thankx friends I got the answer... thankx again --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---