Skip to content

Commit e6cbe90

Browse files
authored
Fixed byId and provide pagination with data type
- Fixed using byId error in active record pattern - Provide pagination with data type (object, array, json)
1 parent 0595c66 commit e6cbe90

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

dbObject.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public function update ($data = null) {
261261
$sqlData = $this->prepareData ();
262262
if (!$this->validate ($sqlData))
263263
return false;
264-
264+
265265
$this->db->where ($this->primaryKey, $this->data[$this->primaryKey]);
266266
return $this->db->update ($this->dbTable, $sqlData);
267267
}
@@ -299,7 +299,7 @@ public function delete () {
299299
*
300300
* @return dbObject|array
301301
*/
302-
protected function byId ($id, $fields = null) {
302+
private function byId ($id, $fields = null) {
303303
$this->db->where (MysqliDb::$prefix . $this->dbTable . '.' . $this->primaryKey, $id);
304304
return $this->getOne ($fields);
305305
}
@@ -438,6 +438,24 @@ private function paginate ($page, $fields = null) {
438438
$this->db->pageLimit = self::$pageLimit;
439439
$res = $this->db->paginate ($this->dbTable, $page, $fields);
440440
self::$totalPages = $this->db->totalPages;
441+
442+
foreach ($res as &$r) {
443+
$this->processArrays ($r);
444+
$this->data = $r;
445+
$this->processAllWith ($r, false);
446+
if ($this->returnType == 'Object') {
447+
$item = new static ($r);
448+
$item->isNew = false;
449+
$objects[] = $item;
450+
}
451+
}
452+
$this->_with = Array();
453+
if ($this->returnType == 'Object')
454+
return $objects;
455+
456+
if ($this->returnType == 'Json')
457+
return json_encode ($res);
458+
441459
return $res;
442460
}
443461

0 commit comments

Comments
 (0)