Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In combination with ordering and will_paginate the sql is broken on postgresql #52

Closed
iNecas opened this issue Apr 10, 2013 · 7 comments

Comments

@iNecas
Copy link

iNecas commented Apr 10, 2013

Example call:

ConfigTemplate.order('name').search_for("name ~ Kickstart Default and kind = PXELinux", {:order=>nil}).paginate({:page=>1})

Produces:

ActiveRecord::StatementInvalid: PGError: ERROR:  syntax error at or near "FIRST"

LINE 1: ...fig_templates".id, "config_templates"."name"NULLS FIRST  AS ...

 SELECT  DISTINCT "config_templates".id, "config_templates"."name"NULLS FIRST  A
S alias_0 FROM "config_templates" LEFT OUTER JOIN "taxable_taxonomies" ON "taxab
le_taxonomies"."taxable_id" = "config_templates"."id" AND "taxable_taxonomies"."
taxable_type" 
@abenari
Copy link
Collaborator

abenari commented Apr 11, 2013

I am failing to reproduce the error.
Please add more information on the environment

@iNecas
Copy link
Author

iNecas commented Apr 11, 2013

Running this against latest develop branch of Foreman on Postre fails for me:

curl -u admin:changeme -k 'http://localhost:3000/api/config_templates?search=name+%7E+Kickstart+Default+and+kind+%3D+PXELinux'

@ohadlevy
Copy link
Contributor

@iNecas does this happens on rails 3.2.13 as well?

@brocktimus
Copy link
Collaborator

I use will_paginate with ordering and scoped search frequently. I think the difference is I never use the order hash in the search_for method. The below works.

Model.where(hash).order(:somefield).page(params[:page]).search_for('some things')

Is there some reason we offer an order clause? It seems like it might have been useful in 2.3 but seems quite redundant now.

@wvanbergen
Copy link
Owner

Scoped search has a default ordering, and you can override it in the query by using the options parameter.
It was added by @abenari in 2011: https://github.com/wvanbergen/scoped_search/tree/f17e94483504bed6f27b025d831f28adb0a945eb

It seems related to the auto completer but I am not quite sure.

@abenari
Copy link
Collaborator

abenari commented Apr 18, 2013

The SQL error above seems to be rails 3.2.8 to 3.2.12 PostgreSQL adapter related and not a scoped_search issue.
I am trying to isolate the problem.

The order functionality in scoped_search was meant to be used with the sorting helpers in:
https://github.com/wvanbergen/scoped_search/blob/master/lib/scoped_search/rails_helper.rb#L15
It is probably redundant now.

@abenari
Copy link
Collaborator

abenari commented Apr 18, 2013

I have managed to reproduce the error with PG and rails 3.2.8 it is gone in rails 3.2.9.
closing this issue as it is not a scoped_search issue.

@abenari abenari closed this as completed Apr 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants