# Order by size desc

**URL:** <https://www.ruby-forum.com/t/order-by-size-desc/158302>\
**Category:** Rails\
**Created:** [January 21, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/order-by-size-desc/158302 "2009-01-21T20:55:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [January 21, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/order-by-size-desc/158302/1 "2009-01-21T20:55:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [January 21, 2009, 11:35pm UTC](https://www.ruby-forum.com/t/order-by-size-desc/158302/2 "2009-01-21T23:35:55Z")

</div>

On Wed, Jan 21, 2009 at 11:54 AM, Dan P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![perezda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/46a35a/32.png) [@perezda](https://www.ruby-forum.com/u/perezda)\
**Post date:** [January 22, 2009, 12:57am UTC](https://www.ruby-forum.com/t/order-by-size-desc/158302/3 "2009-01-22T00:57:17Z")

</div>

Awesome, thanks for the reply i shall give it a try
