diff --git a/orator/orm/builder.py b/orator/orm/builder.py index 72a7441e..ca3f5bcd 100644 --- a/orator/orm/builder.py +++ b/orator/orm/builder.py @@ -286,7 +286,7 @@ def lists(self, column, key=None): results[i] = self._model.new_from_builder(fill).column - def paginate(self, per_page=None, current_page=None, columns=None): + def paginate(self, per_page=None, current_page=None, columns=None, column_count=None): """ Paginate the given query. @@ -296,6 +296,9 @@ def paginate(self, per_page=None, current_page=None, columns=None): :param current_page: The current page of results :type current_page: int + :param column_count: The columns that used to get count + :type column_count: list + :param columns: The columns to return :type columns: list @@ -303,8 +306,10 @@ def paginate(self, per_page=None, current_page=None, columns=None): """ if columns is None: columns = ["*"] + if column_count is None: + column_count = ["*"] - total = self.to_base().get_count_for_pagination() + total = self.to_base().get_count_for_pagination(column_count) page = current_page or Paginator.resolve_current_page() per_page = per_page or self._model.get_per_page() diff --git a/orator/query/builder.py b/orator/query/builder.py index 6e8aaa6c..80f094a6 100644 --- a/orator/query/builder.py +++ b/orator/query/builder.py @@ -1064,7 +1064,7 @@ def _run_select(self): self.to_sql(), self.get_bindings(), not self._use_write_connection ) - def paginate(self, per_page=15, current_page=None, columns=None): + def paginate(self, per_page=15, current_page=None, columns=None, column_count=None): """ Paginate the given query. @@ -1077,15 +1077,20 @@ def paginate(self, per_page=15, current_page=None, columns=None): :param columns: The columns to return :type columns: list + :param column_count: The columns that used to get count + :type column_count: list + :return: The paginator :rtype: LengthAwarePaginator """ if columns is None: columns = ["*"] + if column_count is None: + column_count = ["*"] page = current_page or Paginator.resolve_current_page() - total = self.get_count_for_pagination() + total = self.get_count_for_pagination(column_count) results = self.for_page(page, per_page).get(columns) @@ -1116,10 +1121,10 @@ def simple_paginate(self, per_page=15, current_page=None, columns=None): return Paginator(self.get(columns), per_page, page) - def get_count_for_pagination(self): + def get_count_for_pagination(self, column_count): self._backup_fields_for_count() - total = self.count() + total = self.count(column_count) self._restore_fields_for_count()