# Sorting on a model method?

**URL:** <https://www.ruby-forum.com/t/sorting-on-a-model-method/63587>\
**Category:** Rails\
**Created:** [June 16, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/sorting-on-a-model-method/63587 "2006-06-16T13:22:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/ba8739/32.png) [@jimc](https://www.ruby-forum.com/u/jimc)\
**Post date:** [June 16, 2006, 1:22pm UTC](https://www.ruby-forum.com/t/sorting-on-a-model-method/63587/1 "2006-06-16T13:22:34Z")

</div>

My model stores pieces of data, and I have a method defined in the  
model that aggregates those pieces into a more useful form. I’m trying  
to figure out how to sort with the aggregate …

Currently I have Person has\_many involvements, Person has\_many events  
:through=\>:involvements, and it’s Events that has the aggregate method,  
a ‘date’ field. When I’m holding a Person object, I can step through  
person.involvements and look at the Event from there :-

for i in person.involvements  
i.event.date  
end

But I’d like to do that step through ordered by date 🙂 Please help me  
see what I’ve missed so far …

(The Involvements table is present because many People might be  
Involved in an Event, in different roles – I’m storing the role in the  
Involvement table at the moment. Perhaps I’ve made my life difficult?)

-jim
