Kaminari Not working due to group keyword

@users = User.registred
        .includes(:items)
        .joins('LEFT OUTER JOIN items ON users.id=items.user_id')
        .group(User.column_names.collect do |c| "#{User.table_name}.#{c}" end.join(','))
        .order('CASE WHEN LENGTH(users.profile_picture) > 0 THEN 0 ELSE 1 END, followers_count DESC, bibbed_items_count DESC, SUM(items.user_likes_count) DESC, users.id')

where registered = where("deactivated_at IS NULL AND last_sign_in_at IS NOT NULL")

Kaminari not working with group clause. How to optimized group clause in this query ?

Answers


Had the same issue, fixed it like you - by providing an appropiate id value in the group clause. However, apparently it doesn't need to replace your original group clause - just append an additional call:

@users = User.registred
    .includes(:items)
    .joins('LEFT OUTER JOIN items ON users.id=items.user_id')
    .group(User.column_names.collect do |c| "#{User.table_name}.#{c}" end.join(','))
    .order('CASE WHEN LENGTH(users.profile_picture) > 0 THEN 0 ELSE 1 END, followers_count DESC, bibbed_items_count DESC, SUM(items.user_likes_count) DESC, users.id')
    .group('users.id')

Need Your Help

tiggers orders without explicitly settings?

sql-server triggers

I have a table which has 3 triggers of update (just for the scenario)...

Android - what's a good format for music files?

android audio format music

I have used MP3 in my app but I noticed that it dominates the APK size.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.