# Pagination and model calculated fields

**URL:** <https://www.ruby-forum.com/t/pagination-and-model-calculated-fields/139449>\
**Category:** Rails\
**Created:** [June 4, 2008, 12:53am UTC](https://www.ruby-forum.com/t/pagination-and-model-calculated-fields/139449 "2008-06-04T00:53:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [June 4, 2008, 12:53am UTC](https://www.ruby-forum.com/t/pagination-and-model-calculated-fields/139449/1 "2008-06-04T00:53:04Z")

</div>

class Client has\_many :placements  
class Placement belongs\_to :clients

class Client…  
def current\_client  
if Placement.find(:first,  
:conditions =\> [“discharge\_date IS NULL AND accepted IS true   
AND client\_id = ?”, self])  
return true  
else  
return false  
end  
end

using paginator gem…in my clients\_controller.rb

@pager = ::Paginator.new(Client.count(  
:conditions =\> cond.to\_sql), 12) do |offset, per\_page|  
Client.find(:all, :limit =\> per\_page,  
:conditions =\> cond.to\_sql,  
:include =\> :case\_manager,  
:order =\> sortby,  
:offset =\> offset)  
end

is there any way that I can ‘sort’ by current\_client (not a table field)  
and paginate properly?

Craig
