PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Active-Record Sql: selecting only few columns
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Active-Record Sql: selecting only few columns

Réponse
 
LinkBack Outils de la discussion
Vieux 12/03/2008, 13h27   #1
Rajat Garg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Active-Record Sql: selecting only few columns

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

Hi Guys,

I am writing a sql query -
User.find(:all, 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 .

Thanks

--
Rajat Garg


Ph: 206-499-9495
Add: 1314 Spring Street, #412
Seattle, WA 98104
Web: http://www.pilotoutlook.com
-----------------------------------------------------------------------------------------------------
Flying is the second greatest thrill known to man. Landing is the first!

  Réponse avec citation
Vieux 12/03/2008, 13h57   #2
David Palm
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Active-Record Sql: selecting only few columns

:select should be your friend here.

On Wed, 12 Mar 2008 21:27:51 +0900, Rajat Garg wrote:
> Hi Guys,
>
> I am writing a sql query -
> User.find(:all, 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 .
>
> Thanks


  Réponse avec citation
Vieux 12/03/2008, 13h57   #3
Rob Biedenharn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Active-Record Sql: selecting only few columns

On Mar 12, 2008, at 8:27 AM, Rajat Garg wrote:
> Hi Guys,
>
> I am writing a sql query -
> User.find(:all, 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 .
>
> Thanks
>
> --
> Rajat Garg
>
> Ph: 206-499-9495
> Add: 1314 Spring Street, #412
> Seattle, WA 98104
> Web: http://www.pilotoutlook.com
> -----------------------------------------------------------------------------------------------------
> Flying is the second greatest thrill known to man. Landing is the
> first!



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
Rob@AgileConsultingLLC.com



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 01h56.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08262 seconds with 11 queries