From 1c919c7a0a6de39a951c49768092d30a4d41c7c1 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 2 Aug 2007 21:24:29 +0000 Subject: [PATCH] added whereIn --- lib/Doctrine/Query/Abstract.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index e34845ffb..1e06ae534 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -71,6 +71,35 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate } return $this->parseQueryPart('where', $where, true); } + /** + * whereIn + * adds IN condition to the query WHERE part + * + * @param string $expr + * @param mixed $params an array of parameters or a simple scalar + * @return Doctrine_Query + */ + public function whereIn($params = array()) + { + if (is_array($params)) { + $this->_params = array_merge($this->_params, $params); + } else { + $this->_params[] = $params; + } + $a = array(); + foreach ($params as $k => $value) { + if ($value instanceof Doctrine_Expression) { + $value = $value->getSql(); + unset($values[$k]); + } else { + $value = '?'; + } + $a[] = $value; + } + $where = $expr . ' IN (' . implode(', ', $a) . ')'; + + return $this->parseQueryPart('where', $where, true); + } /** * addGroupBy * adds fields to the GROUP BY part of the query