# Three levels of indirection

**URL:** <https://www.ruby-forum.com/t/three-levels-of-indirection/127376>\
**Category:** Rails\
**Created:** [January 28, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/three-levels-of-indirection/127376 "2008-01-28T18:59:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [January 28, 2008, 6:59pm UTC](https://www.ruby-forum.com/t/three-levels-of-indirection/127376/1 "2008-01-28T18:59:23Z")

</div>

In the following hypothetical scenario, I’d like to associate Books  
with Clubs without using finder\_sql. Apparently, if you use  
finder\_sql, all the find\_in\_collection methods are not added to the  
associated objects. Without which I won’t be able to call  
my\_club.books.find(:all, :conditions =\> ‘is\_read = true’) or to do  
pagination for example.

Class Club \< ActiveRecord::Base  
has\_many :memberships  
has\_many :readers, :through =\> :memberships

```
        #DOES NOT WORK
        #has_many :books, :through => :readers

        #DOES NOT ADD find_in_collection METHODS
        #has_many :books, :finder_sql =>
        # %q{
        # select distinct books.*
        # from books
        # join memberships on books.reader_id

```

= memberships.reader\_id and memberships.club\_id = #{self.id}  
# order by books.read\_at desc  
# }  
end

Class Memberships \< ActiveRecord::Base  
belongs\_to :club  
belongs\_to :reader  
end

Class Reader \< ActiveRecord::Base  
has\_many :memberships  
has\_many :books  
end

Class Book \< ActiveRecord::Base  
belongs\_to :reader  
end

Does anyone have any idea how I can create this association without  
rewriting the find\_in\_collection methods?

Thanks!

---

<div class="post-metadata">

**Author:** ![gsterndale](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@gsterndale](https://www.ruby-forum.com/u/gsterndale)\
**Post date:** [January 28, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/three-levels-of-indirection/127376/2 "2008-01-28T23:10:46Z")

</div>

Perhaps I could write my own find method and extend the association  
proxy? Is there a more elegant way?
