# Sorting activerecord returned timestamps

**URL:** <https://www.ruby-forum.com/t/sorting-activerecord-returned-timestamps/146340>\
**Category:** Rails\
**Created:** [August 20, 2008, 5:34am UTC](https://www.ruby-forum.com/t/sorting-activerecord-returned-timestamps/146340 "2008-08-20T05:34:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![morgan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@morgan](https://www.ruby-forum.com/u/morgan)\
**Post date:** [August 20, 2008, 5:34am UTC](https://www.ruby-forum.com/t/sorting-activerecord-returned-timestamps/146340/1 "2008-08-20T05:34:10Z")

</div>

So i have and object with an attribute that contains a bunch more  
attributes.  
i would like to sort the schedules by the sched\_timestart field which is  
a datetime stamp

user-  
—name  
|  
—schedules  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
user-  
—name  
|  
—schedules  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart  
|---- sched\_timestart

---

<div class="post-metadata">

**Author:** ![morgan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@morgan](https://www.ruby-forum.com/u/morgan)\
**Post date:** [August 20, 2008, 12:31pm UTC](https://www.ruby-forum.com/t/sorting-activerecord-returned-timestamps/146340/2 "2008-08-20T12:31:19Z")

</div>

> So i have and object with an attribute that contains a bunch more  
> attributes.

do you mean a many-to-many relation? I.e:

class User \< AR::Base  
has\_many :schedules  
end

if so, heres how you order:

class User \< AR::Base  
has\_many :schedules, :order =\> ‘shed\_timestart ASC’  
end

ASC can be replaced by DESC. ASC is ascending (biggest at top,  
smallest at bottom), DESC is descending.

On Aug 20, 4:34 am, Morgan M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![morgan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/0ea827/32.png) [@morgan](https://www.ruby-forum.com/u/morgan)\
**Post date:** [August 20, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/sorting-activerecord-returned-timestamps/146340/3 "2008-08-20T15:21:34Z")

</div>

you are a geeeeeennnniiiiiuuusss… i’ve just been going the wrong  
direction.
