Forum: Ruby on Rails Pagination and Parent Conditions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F2a8e4cc069558b818508c80052f2f5e?d=identicon&s=25 Brent Johnson (Guest)
on 2006-04-04 21:44
(Received via mailing list)
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
6661ef9d747db3af8896cd94959d717d?d=identicon&s=25 Paul Barry (Guest)
on 2006-04-04 21:51
(Received via mailing list)
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/ActionControlle...
F2a8e4cc069558b818508c80052f2f5e?d=identicon&s=25 Brent Johnson (Guest)
on 2006-04-04 22:12
(Received via mailing list)
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
This topic is locked and can not be replied to.