Commit e670e2ab authored by mahono's avatar mahono

added possibility to use an aliase with Doctrine_Table->createQuery() and some...

added possibility to use an aliase with Doctrine_Table->createQuery() and some very small refactoring using createQuery() in Doctrine_Table
parent 8bef0c7c
...@@ -597,11 +597,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -597,11 +597,16 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* creates a new Doctrine_Query object and adds the component name * creates a new Doctrine_Query object and adds the component name
* of this table as the query 'from' part * of this table as the query 'from' part
* *
* @param string Optional alias name for component aliasing.
*
* @return Doctrine_Query * @return Doctrine_Query
*/ */
public function createQuery() public function createQuery($alias = '')
{ {
return Doctrine_Query::create()->from($this->getComponentName()); if (!empty($alias)) {
$alias = ' ' . trim($alias);
}
return Doctrine_Query::create($this->_conn)->from($this->getComponentName() . $alias);
} }
/** /**
* getRepository * getRepository
...@@ -836,23 +841,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -836,23 +841,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
->where(implode(' = ? AND ', (array) $this->_identifier) . ' = ?') ->where(implode(' = ? AND ', (array) $this->_identifier) . ' = ?')
->fetchOne($id, $hydrationMode); ->fetchOne($id, $hydrationMode);
} }
/**
* applyInheritance
* @param $where query where part to be modified
* @return string query where part with column aggregation inheritance added
*/
final public function applyInheritance($where)
{
if ( ! empty($this->options['inheritanceMap'])) {
$a = array();
foreach ($this->options['inheritanceMap'] as $field => $value) {
$a[] = $field . ' = ?';
}
$i = implode(' AND ', $a);
$where .= ' AND ' . $i;
}
return $where;
}
/** /**
* findAll * findAll
* returns a collection of records * returns a collection of records
...@@ -862,9 +850,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -862,9 +850,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/ */
public function findAll($hydrationMode = null) public function findAll($hydrationMode = null)
{ {
$graph = new Doctrine_Query($this->_conn); return $this->createQuery()->execute(array(), $hydrationMode);
$users = $graph->query('FROM ' . $this->options['name'], array(), $hydrationMode);
return $users;
} }
/** /**
* findByDql * findByDql
...@@ -876,13 +862,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -876,13 +862,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD * @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD
* @return Doctrine_Collection * @return Doctrine_Collection
*/ */
public function findBySql($dql, array $params = array(), $hydrationMode = null) { 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, $hydrationMode); return $this->createQuery()->where($dql)->execute($params, $hydrationMode);
return $users;
} }
public function findByDql($dql, array $params = array(), $hydrationMode = null) { public function findByDql($dql, array $params = array(), $hydrationMode = null)
{
return $this->findBySql($dql, $params, $hydrationMode); return $this->findBySql($dql, $params, $hydrationMode);
} }
/** /**
...@@ -1028,6 +1014,23 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1028,6 +1014,23 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
} }
return $this->getRecord(); return $this->getRecord();
} }
/**
* applyInheritance
* @param $where query where part to be modified
* @return string query where part with column aggregation inheritance added
*/
final public function applyInheritance($where)
{
if ( ! empty($this->options['inheritanceMap'])) {
$a = array();
foreach ($this->options['inheritanceMap'] as $field => $value) {
$a[] = $field . ' = ?';
}
$i = implode(' AND ', $a);
$where .= ' AND ' . $i;
}
return $where;
}
/** /**
* count * count
* *
...@@ -1291,9 +1294,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable ...@@ -1291,9 +1294,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
} }
public function unshiftFilter(Doctrine_Record_Filter $filter) public function unshiftFilter(Doctrine_Record_Filter $filter)
{ {
$filter->setTable($this); $filter->setTable($this);
$filter->init(); $filter->init();
array_unshift($this->_filters, $filter); array_unshift($this->_filters, $filter);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment