Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
ggilder opened this Issue · 0 comments

2 participants

@ggilder

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 ggilder referenced this issue from a commit in ggilder/active_admin
Gabriel Gilder fix SQL error with unquoted column names (#971)
- 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
7ba3487
@gregbell gregbell was assigned
@gregbell gregbell closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.