diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index 08252c420..1f4550d8c 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1584,7 +1584,7 @@ class BasicEntityPersister ); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 1a5bd8e51..190ae7be6 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -328,17 +328,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn; } - - // Filters for each parent table - $filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias, $parentClass->table['name']); - if('' !== $filterSql) { - if (!$first) $joinSql .= ' AND '; - $joinSql .= $filterSql; - } } - //@todo: filters for the sub tables of childs - // OUTER JOIN sub tables foreach ($this->_class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); @@ -398,13 +389,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $lockSql = ' ' . $this->_platform->getWriteLockSql(); } - // Filters for the base table - $filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias, $this->_class->table['name']); - if('' !== $filterSql) { - if($conditionSql) $conditionSql .= ' AND '; - $conditionSql .= $filterSql; - } - return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql . ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias . $joinSql @@ -490,13 +474,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $this->_class->setFieldValue($entity, $this->_class->versionField, $value); } - private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) { $filterSql = ''; $first = true; foreach($this->_em->getFilters()->getEnabledFilters() as $filter) { - if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias, $targetTable)) { + if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { if ( ! $first) $filterSql .= ' AND '; else $first = false; $filterSql .= '(' . $filterExpr . ')'; } diff --git a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php index 6ffe2b6de..81cae335a 100644 --- a/lib/Doctrine/ORM/Query/Filter/SQLFilter.php +++ b/lib/Doctrine/ORM/Query/Filter/SQLFilter.php @@ -73,5 +73,5 @@ abstract class SQLFilter /** * @return string The constraint if there is one, empty string otherwise */ - abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = ''); + abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 92016bc69..107b4ca84 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -449,44 +449,6 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($user->groups->slice(0,10))); } - public function testJoinSubclassPersister_FilterOnBaseTable() - { - $this->loadCompanyFixtureData(); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); - - // Enable the filter - $conf = $this->_em->getConfiguration(); - $conf->addFilter("manager_title", "\Doctrine\Tests\ORM\Functional\CompanyManagerTitleFilter"); - $this->_em->getFilters() - ->enable("manager_title") - ->setParameter("title", "devlead", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); - - $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); - $this->assertEquals(1, count($managers)); - $this->assertEquals("Guilherme", $managers[0]->getName()); - } - - public function testJoinSubclassPersister_FilterOnParentTable() - { - $this->loadCompanyFixtureData(); - $this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll())); - - // Enable the filter - $conf = $this->_em->getConfiguration(); - $conf->addFilter("employee_department", "\Doctrine\Tests\ORM\Functional\CompanyEmployeeDepartmentFilter"); - $this->_em->getFilters() - ->enable("employee_department") - ->setParameter("department", "parsers", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType()); - - $this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - - $managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll(); - $this->assertEquals(1, count($managers)); - $this->assertEquals("Guilherme", $managers[0]->getName()); - } - private function loadFixtureData() { $user = new CmsUser; @@ -574,7 +536,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase class MySoftDeleteFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") { return ""; @@ -586,7 +548,7 @@ class MySoftDeleteFilter extends SQLFilter class MyLocaleFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) { return ""; @@ -598,7 +560,7 @@ class MyLocaleFilter extends SQLFilter class CMSCountryFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") { return ""; @@ -610,7 +572,7 @@ class CMSCountryFilter extends SQLFilter class CMSGroupPrefixFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") { return ""; @@ -621,7 +583,7 @@ class CMSGroupPrefixFilter extends SQLFilter } class CMSArticleTopicFilter extends SQLFilter { - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') + public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) { if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") { return ""; @@ -630,27 +592,3 @@ class CMSArticleTopicFilter extends SQLFilter return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value. } } - -class CompanyManagerTitleFilter extends SQLFilter -{ - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') - { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyManager") { - return ""; - } - - return $targetTableAlias.'.title = ' . $this->getParameter('title'); // getParam uses connection to quote the value. - } -} - -class CompanyEmployeeDepartmentFilter extends SQLFilter -{ - public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '') - { - if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEmployee") { - return ""; - } - - return $targetTableAlias.'.department = ' . $this->getParameter('department'); // getParam uses connection to quote the value. - } -}