I want this query into ror form select name from Batch where id = 1 i want only name i tried Batch.find(:all, :conditions => {:id => 1}) it works but Batch.find(:name, :conditions => {:id => 1}) not work please give me suggestion -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Batch.where(:id => 1).select(:name) On Thu, Feb 16, 2012 at 1:09 PM, $wapnil Patil <swapnil.patil04-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I want this query into ror form > select name from Batch where id = 1 > i want only name > i tried > Batch.find(:all, :conditions => {:id => 1}) it works > but > Batch.find(:name, :conditions => {:id => 1}) not work > please give me suggestion > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Josh Software Private Limited <http://www.joshsoftware.com> 6, Thube Park, Shivaji Nagar, Pune - 411005 Office: +91-020-25539995 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If you are using Rails 3, you can do Batch.select(:name).find(1) On Thu, Feb 16, 2012 at 6:23 PM, Sanjiv Jha <sanjiv-LmeKiT3xSvsi8rCdYzckzA@public.gmane.org> wrote:> Batch.where(:id => 1).select(:name) > > > On Thu, Feb 16, 2012 at 1:09 PM, $wapnil Patil <swapnil.patil04-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> I want this query into ror form >> select name from Batch where id = 1 >> i want only name >> i tried >> Batch.find(:all, :conditions => {:id => 1}) it works >> but >> Batch.find(:name, :conditions => {:id => 1}) not work >> please give me suggestion >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > Josh Software Private Limited <http://www.joshsoftware.com> > > 6, Thube Park, > Shivaji Nagar, > Pune - 411005 > Office: +91-020-25539995 > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Either I will find a way or I shall make a way -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I guess you are using Raiils 2.*, in rails 2.x, it should be Batch.find(:all, :conditions => {:id => 1}, :select => "name") -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/BtyvBbi1ypAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.