Created
January 19, 2015 20:53
-
-
Save aceat64/551b8b37541b8dec72fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AssetsController.php: | |
<?php | |
public $paginate = array( | |
// The default number of rows to show on a page | |
'limit' => 100, | |
// The max number of rows that can be shown on a page | |
'maxLimit' => 1000, | |
// Use custom find so we can sort by 2nd level associated models | |
'findType' => 'deepList', | |
); | |
public function index() | |
{ | |
// Tell paginator to use our paginate settings | |
$this->Paginator->settings = $this->paginate; | |
// Send to $assets to our view | |
$this->set('assets', $this->Paginator->paginate( | |
'Asset', | |
array(), | |
array( | |
'id', | |
'serial_number', | |
'asset_tag', | |
'service_id', | |
'asset_attribute_count', | |
'EquipmentManufacturer.name', | |
'EquipmentType.name', | |
'EquipmentModel.name', | |
'Depot.name', | |
) | |
)); | |
} | |
?> | |
Asset.php: | |
<?php | |
/** | |
* _findDeepList - Custom finder so we can sort on EquipmentManufacturer.name | |
*/ | |
protected function _findDeepList($state, $query, $results = array()) | |
{ | |
// Only modify things BEFORE the query is run | |
if ($state === 'before') { | |
$query['fields'] = array('Asset.*','EquipmentModel.*','EquipmentManufacturer.*','EquipmentType.*','Depot.*'); | |
$query['joins'] = array( | |
array( | |
'table' => 'equipment_manufacturers', | |
'alias' => 'EquipmentManufacturer', | |
'type' => 'LEFT', | |
'conditions' => array( | |
'EquipmentModel.equipment_manufacturer_id = EquipmentManufacturer.id' | |
) | |
), | |
array( | |
'table' => 'equipment_types', | |
'alias' => 'EquipmentType', | |
'type' => 'LEFT', | |
'conditions' => array( | |
'EquipmentModel.equipment_type_id = EquipmentType.id' | |
) | |
), | |
); | |
// Return the modified query | |
return $query; | |
} | |
// Do nothing, return the results | |
return $results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When using Postgres I get this error, MySQL (actually MariaDB) works:
Notice (8): Trying to get property of non-object [CORE/Cake/Model/Datasource/Database/Postgres.php, line 410]
Fatal Error
Error: Call to a member function schema() on a non-object
File: /var/www/asset-tracker/lib/Cake/Model/Datasource/Database/Postgres.php
Line: 410