From 13b5346a4f0f678ba4eae4562f16093f4dcb41df Mon Sep 17 00:00:00 2001 From: adamthehutt Date: Tue, 11 Dec 2007 23:03:57 +0000 Subject: [PATCH] Fix for #669 --- lib/Doctrine/Table.php | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 819925c7c..f64fc762e 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1146,6 +1146,24 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable return $this->createQuery()->execute(array(), $hydrationMode); } + /** + * findBySql + * finds records with given SQL where clause + * returns a collection of records + * + * @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 + * + * @todo This actually takes DQL, not SQL, but it requires column names + * instead of field names. This should be fixed to use raw SQL instead. + */ + public function findBySql($dql, array $params = array(), $hydrationMode = null) + { + return $this->createQuery()->where($dql)->execute($params, $hydrationMode); + } + /** * findByDql * finds records with given DQL where clause @@ -1156,14 +1174,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable * @param int $hydrationMode Doctrine::FETCH_ARRAY or Doctrine::FETCH_RECORD * @return Doctrine_Collection */ - public function findBySql($dql, array $params = array(), $hydrationMode = null) - { - return $this->createQuery()->where($dql)->execute($params, $hydrationMode); - } - public function findByDql($dql, array $params = array(), $hydrationMode = null) { - return $this->findBySql($dql, $params, $hydrationMode); + $parser = new Doctrine_Query($this->_conn); + $component = $this->getComponentName(); + $query = 'FROM ' . $component . ' WHERE ' . $dql; + + return $parser->query($query, $params, $hydrationMode); } /**