Active-Record Sql: selecting only few columns

R

Rajat Garg

[Note: parts of this message were removed to make it a legal post.]

Hi Guys,

I am writing a sql query -
User.find:)all, :eek:rder=> 'u.created_on DESC', :limit =>2,
:joins => "as u left join photos p on u.id = p.user_id")

But i want this query to return only 3 parameters (name, photo_url, id)
instead of all. Is there any ActiveRecord Way of selecting only those
fields.

I will really appreciate your help.

Thanks

--
Rajat Garg


Ph: 206-499-9495
Add: 1314 Spring Street, #412
Seattle, WA 98104
Web: http://www.pilotoutlook.com
 
R

Rob Biedenharn

Hi Guys,

I am writing a sql query -
User.find:)all, :eek:rder=> 'u.created_on DESC', :limit =>2,
:joins => "as u left join photos p on u.id = p.user_id")

But i want this query to return only 3 parameters (name, photo_url,
id)
instead of all. Is there any ActiveRecord Way of selecting only those
fields.

I will really appreciate your help.

Thanks

--
Rajat Garg

Ph: 206-499-9495
Add: 1314 Spring Street, #412
Seattle, WA 98104
Web: http://www.pilotoutlook.com


Add a :select => 'name, photo_url, id' to your User.find, but be aware
that it means the User objects will be readonly since they don't have
enough information to construct the SQL update command later.

-Rob

Rob Biedenharn http://agileconsultingllc.com
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top