Paginate with :order AND :include?

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!

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

Worked great. Thanks!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs