leikind / wice_grid

A Rails grid plugin to create grids with sorting, pagination, and (automatically generated) filters
MIT License
537 stars 213 forks source link

undefined method `<=' for #<ActiveSupport::OrderedHash:0xf070b34> #170

Closed GarPit closed 10 years ago

GarPit commented 10 years ago

This happens in method 'pagination_info' when I have 'group' in query.

if (! allow_showing_all_records) || collection_total_entries <= collection.length

In this case collection_total_entries is a Hash similar to this one:

{64=>1, 63=>1, 62=>1, 61=>1, 60=>1...
leikind commented 10 years ago

Show me your code please

GarPit commented 10 years ago
def initialize(repository = BackOfficeUser.scoped)
  @repository = repository.joins(:roles).joins(
    "INNER JOIN (VALUES #{roles}) as translated_roles(name, translated) ON back_office_roles.name = translated_roles.name"
  ).select("back_office_users.*, string_agg(translated_roles.translated, ', ') as translated_roles_names").group("back_office_users.id")
end
leikind commented 10 years ago

How is this code related to WiceGrid? Where is an initialize_grid call?

GarPit commented 10 years ago

Here it is:

@back_office_users_grid = initialize_grid(
  BackOfficeUser::FilterForSysAdminQuery.new.build(params[:search]),
  order: 'back_office_users.created_at',
  order_direction: 'desc',
  custom_order: {
    'back_office_roles.name' => 'translated_roles_names'
  }
)
GarPit commented 10 years ago

FilterForSysAdminQuery will call initialize and return ActiveRelation

leikind commented 10 years ago

I will take a closer look but I seriously doubt that WiceGrid can work correctly with group.

GarPit commented 10 years ago

Yes, seems you're right. But it's not so difficult to add support for this. I use this workaround:

        collection_total_entries_count = collection_total_entries.is_a?(Hash) ? collection_total_entries.count : collection_total_entries
leikind commented 10 years ago

As I do not have much time for this plugin I would welcome any pull request. Бельгийское пиво за мной :)

GarPit commented 10 years ago

Ok :+1:

kabturek commented 10 years ago

generally the problem is that collection.size returns a hash for grouped queries. collection.length returns the number of grouped records.

GarPit commented 10 years ago

Yes, exactly