# Adding :order to the find method using a self-referencing model

**URL:** <https://www.ruby-forum.com/t/adding-order-to-the-find-method-using-a-self-referencing-model/120827>\
**Category:** Rails\
**Created:** [November 20, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/adding-order-to-the-find-method-using-a-self-referencing-model/120827 "2007-11-20T22:27:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![carp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a8b319/32.png) [@carp](https://www.ruby-forum.com/u/carp)\
**Post date:** [November 20, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/adding-order-to-the-find-method-using-a-self-referencing-model/120827/1 "2007-11-20T22:27:17Z")

</div>

My issue is with a single table, Conferences, that uses a column  
parent\_id to reference itself. This way, I identify big conferences  
(like NCAA) and the smaller conferences that make it up (like PAC  
10). What I’d like to do is use the :order modifier of the find  
method to sort each conference by it’s parent’s name. The best I’ve  
gotten so far is being able to sort by the parent’s ID (which isn’t  
particularly helpful).

One thought was to change my reference column from parent\_id to  
parent\_name (and force these to be unique). However, I’m guessing  
that would break the :counter\_cache functionality. Anyone know what I  
should do? Thanks.

#model  
class Conference \< ActiveRecord::Base  
has\_many :teams  
belongs\_to :conference, :foreign\_key =\> “parent\_id”, :counter\_cache  
=\> true  
end

#table columns  
id  
name  
abbr  
parent\_id  
conferences\_count  
teams\_count

#controller  
@conferences = Conference.find(:all, :order =\> ‘parent\_id’)
