Now the ZZZ is the interesting part. All it should be in @foo.size but I can't recursively call that in the same expression. Which means I have to put the same sql statement in my code ahead of this one just to call .size on it for will_paginate. There's got to be a better way, right? Can I avoid:

Re: Have 2 SQL queries would like only one..

The way pagination works is it only returns the records it needs to display on one page, that is why you need to supply the total records (so it can calculate how many pages there are). I'm afraid there's no way around it. You'll need to send two queries.

However, you can use count_by_sql for better performance on the first query.