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

Bug: Invalid SQL when sorting tables with a column named "group" #971

Closed
ggilder opened this issue Feb 3, 2012 · 0 comments
Closed

Bug: Invalid SQL when sorting tables with a column named "group" #971

ggilder opened this issue Feb 3, 2012 · 0 comments
Assignees
Milestone

Comments

@ggilder
Copy link

ggilder commented Feb 3, 2012

If I use ActiveAdmin to manage a model with a field named "group", and I include that field as a column in the index, then clicking on the column header to sort by group produces the following error:

SQLite3::SQLException: near "group": syntax error: SELECT  "mymodel".* FROM "mymodel"  ORDER BY "mymodel".group desc LIMIT 30 OFFSET 0

It looks to me like the column name should be quoted as well - I traced this down to lib/active_admin/resource_controller/collection.rb, line 53 as of commit 813c86b. It works correctly for me if I change that line to:

table_column = (column =~ /\./) ? column : "#{table}.`#{column}`"

But I'm getting a hard Ruby crash trying to run the test suite, so I'm not able to see what other things that might affect.

Thoughts?

-Gabriel

ggilder pushed a commit to ggilder/active_admin that referenced this issue Feb 6, 2012
- Add ActiveAdmin::Resource#resource_quoted_column_name to provide access to ActiveRecord's built-in column name quoting
- Modify ActiveAdmin::ResourceController::Collection::BaseCollection::Sorting#sort_order to quote the column name used in sorting
- Modify spec for ActiveAdmin::ResourceController::Collection to reflect expectation of having column name quoted
gregbell added a commit that referenced this issue Feb 14, 2012
fix SQL error with unquoted column names (#971)
@ghost ghost assigned gregbell Feb 14, 2012
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

2 participants