Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use db service from the model when paginating #12960

Merged
merged 2 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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