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

ActiveAdmin.default_sort_order "id_desc" prevents use of scopes with joins #38

Closed
urbanautomaton opened this issue May 14, 2011 · 0 comments
Assignees
Labels
Milestone

Comments

@urbanautomaton
Copy link

Hi,

I'm using a model with some scopes involving joins. For example:

class User < ActiveRecord::Base
...
  def self.popular
    joins('LEFT JOIN followings ON users.id = followings.followee_id').
    group('users.id').
    where('COUNT(users.id) > 10')
  end
...
end

If I add this scope to my ActiveAdmin config, I get the following error when viewing the Users index:

Mysql2::Error: Column 'id' in order clause is ambiguous: SELECT COUNT(*) AS count_all, users.id AS users_id FROM `users` LEFT JOIN followings ON users.id = followings.followee_id GROUP BY users.id WHERE COUNT(users.id) > 10 ORDER BY id desc

This appears to be because in lib/active_admin.rb the default sort order is set to "id_desc", which doesn't then get scoped with the appropriate table name - hence the ambiguous query error.

There's a gist here with the full stack trace in case it's useful...

Cheers,
Simon

p.s. thanks for a wonderful tool, by the way - I'm really loving what I've seen of it so far.

@ghost ghost assigned gregbell May 14, 2011
@pcreux pcreux closed this as completed in b01cd5d May 26, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants