diff --git a/Controller/AuditsController.php b/Controller/AuditsController.php index dc892b8..8f086c4 100644 --- a/Controller/AuditsController.php +++ b/Controller/AuditsController.php @@ -21,30 +21,27 @@ public function beforeFilter() { } public function admin_index() { + $this->Paginator->settings['fields'] = [ + 'Audit.id', + 'Audit.event', + 'Audit.model', + 'Audit.entity_id', + 'Audit.description', + 'Audit.source_id', + 'Audit.created', + 'Audit.delta_count', + ]; + $this->Crud->on('beforePaginate', function($event) { if ($model = $this->request->query('model')) { $Instance = ClassRegistry::init($model); $displayField = $Instance->displayField; - - $this->Paginator->settings['fields'] = [ - 'Audit.id', - 'Audit.event', - 'Audit.model', - 'Audit.entity_id', - 'Audit.description', - 'Audit.source_id', - 'Audit.created', - 'Audit.delta_count', - $model . '.' . $displayField - ]; - + $this->Paginator->settings['fields'][] = $model . '.' . $displayField; $this->Paginator->settings['joins'][] = [ 'alias' => $model, 'table' => $Instance->useTable, - 'conditions' => [ - $Instance->alias . '.id = Audit.entity_id' - ], + 'conditions' => [$Instance->alias . '.id = Audit.entity_id'], 'type' => 'INNER' ]; diff --git a/Model/Audit.php b/Model/Audit.php index dc3bb98..8f3483c 100644 --- a/Model/Audit.php +++ b/Model/Audit.php @@ -27,4 +27,16 @@ public function setupSearchPlugin() { $this->Behaviors->load('Search.Searchable'); } +/** + * Make sure not to include any join's in the COUNT(*) from paginator + * + * @param array $conditions + * @param integer $recursive + * @param array $extra + * @return integer + */ + public function paginateCount($conditions, $recursive, $extra) { + return $this->find('count', compact('conditions')); + } + }