Skip to content

Commit

Permalink
Use db service from the model when paginating (#12960)
Browse files Browse the repository at this point in the history
Update CHANGELOG.md
  • Loading branch information
dnapierata authored and sergeyklay committed Jul 17, 2017
1 parent 24c1cd3 commit de4d075
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# [3.2.2](https://github.com/phalcon/cphalcon/releases/tag/v3.2.2) (2017-XX-XX)
- Fixed `Phalcon\Db\Adapter\Pdo\Postgresql::describeColumns` to work properly with `DOUBLE PRECISION` and `REAL` data types [#12842](https://github.com/phalcon/cphalcon/issues/12842)
- Fixed `Phalcon\Paginator\Adapter\QueryBuilder::getPaginate` to use the db connection service of the model [#12957](https://github.com/phalcon/cphalcon/issues/12957)

# [3.2.1](https://github.com/phalcon/cphalcon/releases/tag/v3.2.1) (2017-07-10)
- Added `Phalcon\Db\Dialect\Mysql::getForeignKeyChecks` to generate a SQL to check the foreign key settings [#2604](https://github.com/phalcon/cphalcon/issues/2604), [phalcon/phalcon-devtools#556](https://github.com/phalcon/phalcon-devtools/issues/556)
Expand Down
11 changes: 9 additions & 2 deletions phalcon/paginator/adapter/querybuilder.zep
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ class QueryBuilder extends Adapter
{
var originalBuilder, builder, totalBuilder, totalPages,
limit, numberPage, number, query, page, before, items, totalQuery,
result, row, rowcount, next, sql, columns, db, hasHaving, hasGroup;
result, row, rowcount, next, sql, columns, db, hasHaving, hasGroup,
model, modelClass, dbService;

let originalBuilder = this->_builder;
let columns = this->_columns;
Expand Down Expand Up @@ -224,7 +225,13 @@ class QueryBuilder extends Adapter
*/
if hasHaving {
let sql = totalQuery->getSql();
let db = totalBuilder->getDI()->get("db");
let modelClass = builder->_models;
if typeof modelClass == "array" {
let modelClass = array_values(modelClass)[0];
}
let model = new {modelClass}();
let dbService = model->getReadConnectionService();
let db = totalBuilder->getDI()->get(dbService);
let row = db->fetchOne("SELECT COUNT(*) as rowcount FROM (" . sql["sql"] . ") as T1", Db::FETCH_ASSOC, sql["bind"]),
rowcount = row ? intval(row["rowcount"]) : 0,
totalPages = intval(ceil(rowcount / limit));
Expand Down

0 comments on commit de4d075

Please sign in to comment.