# Pagination and Parent Conditions

**URL:** <https://www.ruby-forum.com/t/pagination-and-parent-conditions/56845>\
**Category:** Rails\
**Created:** [April 4, 2006, 9:44pm UTC](https://www.ruby-forum.com/t/pagination-and-parent-conditions/56845 "2006-04-04T21:44:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brent\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Brent\_J](https://www.ruby-forum.com/u/Brent_J)\
**Post date:** [April 4, 2006, 9:44pm UTC](https://www.ruby-forum.com/t/pagination-and-parent-conditions/56845/1 "2006-04-04T21:44:54Z")

</div>

Can I do any “fancy” conditionals when using the Pagination helper?  
The problem is that I want to be able to specify a conditional based  
on the criteria of a parent object. Here’s an example:

Object A has\_many Object B’s

I want to paginate through 100 B’s but I _only_ want it to return the  
ones who’s A.flag = true

I poked around through the Wiki and list archive but didn’t see  
anything.

Thanks,

- Brent

---

<div class="post-metadata">

**Author:** ![Brent\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Brent\_J](https://www.ruby-forum.com/u/Brent_J)\
**Post date:** [April 4, 2006, 9:51pm UTC](https://www.ruby-forum.com/t/pagination-and-parent-conditions/56845/2 "2006-04-04T21:51:12Z")

</div>

I would assume this can be done using a combination of the :conditions  
and  
:joins options of the paginate method

[http://api.rubyonrails.org/classes/ActionController/Pagination.html#M000103](http://api.rubyonrails.org/classes/ActionController/Pagination.html#M000103)

---

<div class="post-metadata">

**Author:** ![Brent\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Brent\_J](https://www.ruby-forum.com/u/Brent_J)\
**Post date:** [April 4, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/pagination-and-parent-conditions/56845/3 "2006-04-04T22:12:54Z")

</div>

Wow, I looked directly at the pagination page and I missed the :joins  
option. I did manage to find a workaround, but it’s not near as clean  
as using the :joins option. I found a method called  
paginate\_collection, so I pulled and filtered the results and called  
that instead of the pagination helper. Using the join will work much  
better (especially as the tables grow).

Thanks,

- Brent
