Added FETCH_ARRAY support for table finder methods, fixes bug #397
This commit is contained in:
parent
202d66860b
commit
9b5246368e
@ -677,14 +677,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
||||
*
|
||||
* @param string $query DQL query
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @see Doctrine_Query
|
||||
* @return Doctrine_Collection Collection of Doctrine_Record objects
|
||||
*/
|
||||
public function query($query, array $params = array())
|
||||
public function query($query, array $params = array(), $hydrationMode = null)
|
||||
{
|
||||
$parser = new Doctrine_Query($this);
|
||||
|
||||
return $parser->query($query, $params);
|
||||
return $parser->query($query, $params, $hydrationMode);
|
||||
}
|
||||
/**
|
||||
* prepare
|
||||
|
@ -1522,14 +1522,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
*
|
||||
* @param string $query DQL query
|
||||
* @param array $params prepared statement parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @see Doctrine::FETCH_* constants
|
||||
* @return mixed
|
||||
*/
|
||||
public function query($query, $params = array())
|
||||
public function query($query, $params = array(), $hydrationMode = null)
|
||||
{
|
||||
$this->parseQuery($query);
|
||||
|
||||
return $this->execute($params);
|
||||
return $this->execute($params, $hydrationMode);
|
||||
}
|
||||
|
||||
public function copy(Doctrine_Query $query = null)
|
||||
|
@ -853,10 +853,14 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
* finds a record by its identifier
|
||||
*
|
||||
* @param $id database row id
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Record|false a record for given database identifier
|
||||
*/
|
||||
public function find($id)
|
||||
public function find($id, $hydrationMode = null)
|
||||
{
|
||||
if ($hydrationMode === null) {
|
||||
$hydrationMode = Doctrine::FETCH_RECORD;
|
||||
}
|
||||
if ($id !== null) {
|
||||
if ( ! is_array($id)) {
|
||||
$id = array($id);
|
||||
@ -867,14 +871,23 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
$records = Doctrine_Query::create()
|
||||
->from($this->getComponentName())
|
||||
->where(implode(' = ? AND ', $this->primaryKeys) . ' = ?')
|
||||
->execute($id);
|
||||
->execute($id, $hydrationMode);
|
||||
|
||||
if (count($records) === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($hydrationMode) {
|
||||
case Doctrine::FETCH_RECORD:
|
||||
if (count($records) > 0) {
|
||||
return $records->getFirst();
|
||||
}
|
||||
case Doctrine::FETCH_ARRAY:
|
||||
if (!empty($records[0])) {
|
||||
return $records[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
@ -898,12 +911,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
* findAll
|
||||
* returns a collection of records
|
||||
*
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function findAll()
|
||||
public function findAll($hydrationMode = null)
|
||||
{
|
||||
$graph = new Doctrine_Query($this->conn);
|
||||
$users = $graph->query('FROM ' . $this->options['name']);
|
||||
$users = $graph->query('FROM ' . $this->options['name'], array(), $hydrationMode);
|
||||
return $users;
|
||||
}
|
||||
/**
|
||||
@ -913,16 +927,17 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
|
||||
*
|
||||
* @param string $dql DQL after WHERE clause
|
||||
* @param array $params query parameters
|
||||
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
|
||||
* @return Doctrine_Collection
|
||||
*/
|
||||
public function findBySql($dql, array $params = array()) {
|
||||
public function findBySql($dql, array $params = array(), $hydrationMode = null) {
|
||||
$q = new Doctrine_Query($this->conn);
|
||||
$users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params);
|
||||
$users = $q->query('FROM ' . $this->options['name'] . ' WHERE ' . $dql, $params, $hydrationMode);
|
||||
return $users;
|
||||
}
|
||||
|
||||
public function findByDql($dql, array $params = array()) {
|
||||
return $this->findBySql($dql, $params);
|
||||
public function findByDql($dql, array $params = array(), $hydrationMode = null) {
|
||||
return $this->findBySql($dql, $params, $hydrationMode);
|
||||
}
|
||||
/**
|
||||
* clear
|
||||
|
Loading…
Reference in New Issue
Block a user