Forum: Ruby on Rails Will_paginate with include option

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ank A. (Guest)
on 2009-01-10 19:10
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.
This topic is locked and can not be replied to.