/** * Guess sort column based on their names * Will look primarily for columns named: * 'UpdatedAt', 'UpdatedOn', 'CreatedAt', 'CreatedOn', 'Id' * You can change this sequence by modifying the app_sfPropelFinder_sort_column_guesses value * * @param string $direction 'desc' (default) or 'asc' * * @return sfPropelFinder the current finder object */ public function guessOrder($direction = 'desc') { $columnNames = array(); foreach (sfPropelFinderUtils::getColumnsForPeerClass($this->peerClass) as $c) { $columnNames[] = $c->getPhpName(); } foreach (sfConfig::get('app_sfPropelFinder_sort_column_guesses', array('UpdatedAt', 'UpdatedOn', 'CreatedAt', 'CreatedOn', 'Id')) as $testColumnName) { if (in_array($testColumnName, $columnNames)) { $this->orderBy($testColumnName, $direction); return $this; } } throw new Exception('Unable to figure out the column to use to order rows in sfPropelFinder::guessOrder()'); }
/** * Finds a relation between two classes by introspection */ protected function findRelation($phpName, $peerClass) { foreach (sfPropelFinderUtils::getColumnsForPeerClass($peerClass) as $c) { if ($c->isForeignKey()) { if (!$this->databaseMap->containsTable($c->getRelatedTableName())) { $mapBuilder = call_user_func(array(sfPropelFinderUtils::getPeerClassFromClass($phpName), 'getMapBuilder')); $mapBuilder->doBuild(); } try { $tableMap = $this->databaseMap->getTable($c->getRelatedTableName()); } catch (PropelException $e) { // so $c->getRelatedTable() is not in the database map // even though the $phpName table map has been initialized // we are obviously looking for the wrong table here continue; } if ($tableMap->getPhpName() == $phpName) { return array(constant($peerClass . '::' . $c->getColumnName()), $c->getRelatedName()); } } } return false; }