Changeset 4666

Show
Ignore:
Timestamp:
07/12/08 19:11:44 (12 months ago)
Author:
guilhermeblanco
Message:

Added named query support, which already exists in 2.0. It is not a backport, only a custom implementation to minimize the discrepancies between 1.0 and 2.0. Documentation needed, but I already create a ticket to track for this change.

Location:
branches/1.0
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Table.php

    r4665 r4666  
    12171217        return $record; 
    12181218    } 
     1219     
     1220    /** 
     1221     * adds a named query in the query registry 
     1222     * 
     1223     * @param $queryKey  Query key name 
     1224     * @param $query      DQL string or Doctrine_Query object 
     1225     * @return void 
     1226         */ 
     1227        public function addNamedQuery($queryKey, $query) 
     1228    { 
     1229        $registry = Doctrine_Manager::getInstance()->getQueryRegistry(); 
     1230        $registry->add($this->getComponentName() . '/' . $queryKey, $query); 
     1231    } 
     1232     
     1233    /** 
     1234     * creates a named query in the query registry 
     1235     * 
     1236     * @param $queryKey  Query key name 
     1237     * @return Doctrine_Query 
     1238         */ 
     1239        public function createNamedQuery($queryKey) 
     1240    { 
     1241        return Doctrine_Manager::getInstance()->getQueryRegistry() 
     1242                   ->get($queryKey, $this->getComponentName()); 
     1243    } 
     1244 
    12191245 
    12201246    /** 
     
    13051331    public function execute($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD) 
    13061332    { 
    1307         return Doctrine_Manager::getInstance() 
    1308                             ->getQueryRegistry() 
    1309                             ->get($queryKey, $this->getComponentName()) 
    1310                             ->execute($params, $hydrationMode); 
     1333        return $this->createNamedQuery($queryKey)->execute($params, $hydrationMode); 
    13111334    } 
    13121335 
     
    13251348    public function executeOne($queryKey, $params = array(), $hydrationMode = Doctrine::HYDRATE_RECORD) 
    13261349    { 
    1327         return Doctrine_Manager::getInstance() 
    1328                             ->getQueryRegistry() 
    1329                             ->get($queryKey, $this->getComponentName()) 
    1330                             ->fetchOne($params, $hydrationMode); 
     1350        return $this->createNamedQuery($queryKey)->fetchOne($params, $hydrationMode); 
    13311351    } 
    13321352 
  • branches/1.0/manual/docs/en/dql-doctrine-query-language.txt

    r4605 r4666  
    3939$r->add('User/byName', 'FROM User u WHERE u.name = ?'); 
    4040 
    41 $user = new User(); 
     41$userTable = Doctrine::getTable('User'); 
    4242 
    4343// find the user named Jack Daniels 
    44 $user = $user->findOneByName('Jack Daniels'); 
     44$user = $userTable->findOneByName('Jack Daniels'); 
    4545 
    4646// find all users 
    47 $users = $user->find('all'); 
     47$users = $userTable->find('all'); 
    4848</code> 
    4949