Forum: Ruby on Rails Order by size desc

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
99f81a956dee7db6f6449c78f2ca8e39?d=identicon&s=25 Dan Paul (Guest)
on 2009-01-21 20:55
(Received via mailing list)
ok so i am trying to order the results by the total size in a desc
order, here is what i have so far and its not working

def show
    @reports = Report.find(:all, :group => 'user_id', :order =>
'user_id.size desc' )
end

anybody know how to go about doing this
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2009-01-21 23:35
(Received via mailing list)
On Wed, Jan 21, 2009 at 11:54 AM, Dan Paul <danpaul01@gmail.com> wrote:

>
> ok so i am trying to order the results by the total size in a desc
> order, here is what i have so far and its not working
>
> def show
>    @reports = Report.find(:all, :group => 'user_id', :order =>
> 'user_id.size desc' )
> end
>
> anybody know how to go about doing this


Hi, it seems that you're trying to access an attribute of a User table
called size and
this isn't possible with the above.  Thus, you'll need to do something
like
the following:

Report.all( :joins => :user, :group => "user_id", :order => "size desc"
)


The key thing here is to use :joins to access the users table within the

query.  This allows one to access the fields in the query without
displaying

the data of that attribute.


Good luck,


-Conrad
99f81a956dee7db6f6449c78f2ca8e39?d=identicon&s=25 Dan Paul (Guest)
on 2009-01-22 00:57
(Received via mailing list)
Awesome, thanks for the reply i shall give it a try
This topic is locked and can not be replied to.