Will_paginate with include option


#1

Hello,
I am using will_paginate and want to use eager loading. but when i use
the include and order option i get an error. I am using mssqlserver2000
as database

@people =
Person.paginate(:include=>[:relations],:conditions=>[‘People.id NOT IN
(Select person_id from
people_relations)’],:per_page=>20,:page=>params[:page],:order=>‘last_name
ASC, first_name ASC’)

DBI::DatabaseError: Execute
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
ORDER BY items must appear in the select list if SELECT DISTINCT
is specified.
HRESULT error code:0x80020009
Exception occurred.: SELECT DISTINCT TOP 20 people.id FROM people LEFT
OUTER JOIN people_relations ON people_relations.person_id = people.id
LEFT OUTER JOIN relations ON relations.id = people_relations.relation_id
WHERE (People.id NOT IN (Select person_id from people_relations)) ORDER
BY last_name ASC, first_name ASC

but when i remove the include option it works fine but the results are
not sorted. Please help by last_name.
Thank you.