# Named\_scope on has\_many relationship

**URL:** <https://www.ruby-forum.com/t/named-scope-on-has-many-relationship/147411>\
**Category:** Rails\
**Created:** [September 1, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/named-scope-on-has-many-relationship/147411 "2008-09-01T15:54:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ratcheer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/aca169/32.png) [@ratcheer](https://www.ruby-forum.com/u/ratcheer)\
**Post date:** [September 1, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/named-scope-on-has-many-relationship/147411/1 "2008-09-01T15:54:29Z")

</div>

Hi,  
I have three models: people, visit, place.  
Each time a person visits a place, then a visit is created. I have the  
relationships set up correctly with has\_many through.

I want a simple way to find a list of all the visited (and also  
not-visited) places. i.e. I want to be able to call something like  
Places.visited  
and  
Places.not\_visited

How can I do this? I thought I could do it with a named scope but then I  
realized that there is nothing in the Places table to say if it has been  
visited or not. The only record I have of a place being visited is a  
row in the Visits table.
