# Search by foreign key of foreign key

**URL:** <https://www.ruby-forum.com/t/search-by-foreign-key-of-foreign-key/92397>\
**Category:** Rails\
**Created:** [April 19, 2007, 2:37am UTC](https://www.ruby-forum.com/t/search-by-foreign-key-of-foreign-key/92397 "2007-04-19T02:37:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@andrew](https://www.ruby-forum.com/u/andrew)\
**Post date:** [April 19, 2007, 2:37am UTC](https://www.ruby-forum.com/t/search-by-foreign-key-of-foreign-key/92397/1 "2007-04-19T02:37:51Z")

</div>

Hi,

So far I can sort by foreign key.

@section\_pages, @sections = paginate :sections, :per\_page =\> 20, :order  
=\> sort, :include =\> :title

But how do I sort by a foreign key of the foreign key.

I have “sections” which belong to “courses” which belong to “subjects”.

I want to sort by “prefixes” which is in “subjects”.

Thanks
