Sha256: ace53c19bbb82a4e006ee82aecf2b02f5812bbdbfb0a552937f63545a4a20269

Contents?: true

Size: 742 Bytes

Versions: 2

Compression:

Stored size: 742 Bytes

Contents

module ActiveAdmin
  module Helpers
    module Collection
      # Works around this issue: https://github.com/rails/rails/issues/7121
      #
      # GROUP BY + COUNT drops SELECT statement. This leads to SQL error when
      # the ORDER statement mentions a column defined in the SELECT statement.
      #
      # We remove the ORDER statement to work around this issue.
      def collection_size(collection=collection())
        size = collection.reorder("").count
        # when GROUP BY is used, AR returns Hash instead of Fixnum for .size
        size = size.size if size.kind_of?(Hash)

        size
      end

      def collection_is_empty?(collection=collection())
        collection_size(collection) == 0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin-0.6.6 lib/active_admin/helpers/collection.rb
activeadmin-0.6.5 lib/active_admin/helpers/collection.rb