commit d1bc587650c17bf31dcd5567928a302f32fd2503
parent a37840e655eb5e4a782c8f131b40731564fca7a7
Author: Felicitus <felicitus@felicitus.org>
Date: Fri, 16 Mar 2012 12:49:06 +0100
Added support to query for result fields in joined tables
Diffstat:
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Manager/AbstractManager.php b/src/backend/de/RaumZeitLabor/PartKeepr/Manager/AbstractManager.php
@@ -1,10 +1,10 @@
<?php
namespace de\RaumZeitLabor\PartKeepr\Manager;
-use Doctrine\ORM\Query;
use de\RaumZeitLabor\PartKeepr\Util\Singleton,
de\RaumZeitLabor\PartKeepr\PartKeepr,
Doctrine\ORM\QueryBuilder,
+ Doctrine\ORM\Query,
de\RaumZeitLabor\PartKeepr\Manager\Exceptions\EntityInUseException;
/**
@@ -126,7 +126,12 @@ abstract class AbstractManager extends Singleton {
}
/**
- * Applies pagination to the query
+ * Applies the result fields to the query.
+ *
+ * The result fields can be prefixed with the table alias or not; if not prefixed, it is assumed that we'll be
+ * using the specified entity FQCN.
+ *
+ * Note that the base name will be always "q", so avoid "q" as alias for joined tables.
*
* @param QueryBuilder $qb The query builder
* @param ManagerFilter $filter The query filter
@@ -137,8 +142,15 @@ abstract class AbstractManager extends Singleton {
} else {
// Prepend a prefix to each field
$aQueryFields = array();
- foreach ($this->getQueryFields() as $field) {
- $aQueryFields[] = "q.".$field;
+ foreach ($this->getQueryFields() as $field) {
+
+ if (strpos($field, ".") === false) {
+ // The field is not prefixed, prepend the q. prefix
+ $aQueryFields[] = "q.".$field;
+ } else {
+ // Use as-is
+ $aQueryFields[] = $field;
+ }
}
$qb->select($aQueryFields);