sql query into ror query

8 views
Skip to first unread message

$wapnil Patil

unread,
Feb 16, 2012, 2:39:57 AM2/16/12
to Ruby on Rails: Talk
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

Sanjiv Jha

unread,
Feb 16, 2012, 5:23:11 AM2/16/12
to rubyonra...@googlegroups.com
Batch.where(:id => 1).select(:name)


--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.




--
Josh Software Private Limited

6, Thube Park,
Shivaji Nagar,
Pune - 411005

ppizzq

unread,
Feb 17, 2012, 4:08:14 AM2/17/12
to rubyonra...@googlegroups.com
I guess you are using Raiils 2.*,  in rails 2.x, it should be

Batch.find(:all, :conditions => {:id => 1}, :select => "name")

Paul Lopez

unread,
Feb 16, 2012, 6:49:10 AM2/16/12
to rubyonra...@googlegroups.com
If you are using Rails 3, you can do

Batch.select(:name).find(1)
Either I will find a way or I shall make a way
Reply all
Reply to author
Forward
0 new messages