def collection
      get_collection_ivar || begin
        chain = end_of_association_chain

        # scopes
        chain = apply_scopes(chain)

        # search
        if params[:search]
          chain = chain.search(params[:search].to_s.downcase, match: :all)
        end

        # pagination
        if params[:page]
          per_page = params[:perPage] || 20
          chain    = chain.page(params[:page]).per(per_page)
        else
          chain = chain.all
        end

        set_collection_ivar(chain)
      end
    end
def collection
      get_collection_ivar || begin
        chain = end_of_association_chain

        # scopes
        chain = apply_scopes(chain)

        # search
        if params[:search]
          chain = chain.search(params[:search].to_s.downcase, match: :all)
        end

        # pagination
        if params[:page]
          per_page = params[:perPage] || 20
          chain    = chain.page(params[:page]).per(per_page)
        else
          chain = chain.all
        end

        set_collection_ivar(chain)
      end
    end
add support for scopes, search and pagination