# Paginate with :order AND :include?

**URL:** <https://www.ruby-forum.com/t/paginate-with-order-and-include/87502>\
**Category:** Rails\
**Created:** [March 3, 2007, 3:45am UTC](https://www.ruby-forum.com/t/paginate-with-order-and-include/87502 "2007-03-03T03:45:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [March 3, 2007, 3:45am UTC](https://www.ruby-forum.com/t/paginate-with-order-and-include/87502/1 "2007-03-03T03:45:39Z")

</div>

My two goals:

1. display last 10 posts in reverse chronological order
2. link to the author without hitting the database 2n-1 times

These work:  
def list  
@post\_pages, @posts = paginate :posts, :order =\> “created\_at DESC”,  
:per\_page =\> 10  
end

def list  
@post\_pages, @posts = paginate :posts, :per\_page =\> 10, :include =\>  
:person  
end

This doesn’t:  
def list  
@post\_pages, @posts = paginate :posts, :order =\> “created\_at DESC”,  
:per\_page =\> 10, :include =\> :person  
end

I get a “Column ‘created\_at’ in order clause is ambiguous” error. I’m  
not sure but I thought it was be possible to order the posts and then  
join the person table. Otherwise I will hit the database with each  
post. Does anyone have a solution to this? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [March 3, 2007, 3:55am UTC](https://www.ruby-forum.com/t/paginate-with-order-and-include/87502/2 "2007-03-03T03:55:05Z")

</div>

On Sat, 2007-03-03 at 03:45 +0100, Taylor S. wrote:

> def list  
> I get a “Column ‘created\_at’ in order clause is ambiguous” error. I’m  
> not sure but I thought it was be possible to order the posts and then  
> join the person table. Otherwise I will hit the database with each  
> post. Does anyone have a solution to this? Thanks in advance!

* * *

def list  
@post\_pages, @posts = paginate :posts,  
:order =\> ‘posts.created\_at DESC’  
:per\_page =\> 10,  
:include =\> :person  
end

To clarify ambiguity with two tables that have the same column name, you  
clarify which table to which you are referring.

Craig

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [March 3, 2007, 6:23am UTC](https://www.ruby-forum.com/t/paginate-with-order-and-include/87502/3 "2007-03-03T06:23:42Z")

</div>

Worked great. Thanks!
