Skip to content
New issue

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

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

Already on GitHub? # to your account

default_scope with select() leads to SQL syntax error #2447

Closed
martin-schmidt opened this issue Oct 30, 2015 · 0 comments
Closed

default_scope with select() leads to SQL syntax error #2447

martin-schmidt opened this issue Oct 30, 2015 · 0 comments

Comments

@martin-schmidt
Copy link

An ActiveRecord model with: default_scope { select([:id, :anint, :astring]]) } brings rails_admin to generate a query like: SELECT COUNT(id, anint, astring) FROM "scope_selects") in "controller":"rails_admin/main","action":"dashboard

This leads to: Mysql2::Error - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' id, anint, astring) FROM 'scope_selects'' or
ActiveRecord::StatementInvalid (SQLite3::SQLException: wrong number of arguments to function COUNT(): SELECT COUNT(id, anint, astring) FROM "scope_selects")
when loading the dashboard, because COUNT() does not support multiple keys.

Env:
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
Rails 4.2.4
Gemfile.lock: https://gist.github.com/martin-schmidt/647b982bfa782eeb0e1c
Stacktrace: https://gist.github.com/martin-schmidt/a5fef39cfbb5773a4917
Example: https://github.com/martin-schmidt/rails_admin/commit/354889451900
Failing tests: https://travis-ci.org/martin-schmidt/rails_admin/builds/88326027

Edit:
The broken statement is actually build by AR, but it seems to be the intendent behavior (insert generic rant here) and must be fixed in the application:
rails/rails#15514

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant