# Named scope on belongs\_to

**URL:** <https://www.ruby-forum.com/t/named-scope-on-belongs-to/179872>\
**Category:** Rails\
**Created:** [December 6, 2009, 11:02am UTC](https://www.ruby-forum.com/t/named-scope-on-belongs-to/179872 "2009-12-06T11:02:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 6, 2009, 11:02am UTC](https://www.ruby-forum.com/t/named-scope-on-belongs-to/179872/1 "2009-12-06T11:02:09Z")

</div>

I have a Resort model and a Country model

Resort  
belongs\_to :country

Country  
has\_many :resorts

I tried and failed yesterday to develop a named\_scope that would return  
all the resorts but sorted by country name and then by resort name  
within that country.

How do I do this?

Best

BB

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 6, 2009, 11:16am UTC](https://www.ruby-forum.com/t/named-scope-on-belongs-to/179872/2 "2009-12-06T11:16:27Z")

</div>

mengu in #rubyonrails helped me, thanks!

Here’s the answer…works great.

named\_scope :popular\_by\_country, :joins =\> :country, :conditions =\>  
[‘popular\_resort = ?’, true], :order =\> ‘countries.name ASC’
