File tree Expand file tree Collapse file tree 6 files changed +68
-9
lines changed
Expand file tree Collapse file tree 6 files changed +68
-9
lines changed Original file line number Diff line number Diff line change @@ -85,11 +85,12 @@ And for querying you can use arrays to both DQL and EntityRepositories:
8585 namespace VehicleCatalogue\Model;
8686
8787 // $em is the EntityManager
88- $audi = $em->find("VehicleCatalogue\Model\Car", array( "name" => "Audi A8", "year" => 2010) );
88+ $audi = $em->find("VehicleCatalogue\Model\Car", [ "name" => "Audi A8", "year" => 2010] );
8989
90- $dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.id = ?1";
90+ $dql = "SELECT c FROM VehicleCatalogue\Model\Car c WHERE c.name = ?1 AND c.year = ?2 ";
9191 $audi = $em->createQuery($dql)
92- ->setParameter(1, ["name" => "Audi A8", "year" => 2010])
92+ ->setParameter(1, "Audi A8")
93+ ->setParameter(2, 2010)
9394 ->getSingleResult();
9495
9596 You can also use this entity in associations. Doctrine will then generate two foreign keys one for ``name ``
Original file line number Diff line number Diff line change @@ -1334,6 +1334,12 @@ protected function getSelectColumnsSQL(): string
13341334 $ joinCondition [] = $ this ->getSQLTableAlias ($ association ->sourceEntity , $ assocAlias ) . '. ' . $ sourceCol . ' = '
13351335 . $ this ->getSQLTableAlias ($ association ->targetEntity ) . '. ' . $ targetCol ;
13361336 }
1337+
1338+ // Add filter SQL
1339+ $ filterSql = $ this ->generateFilterConditionSQL ($ eagerEntity , $ joinTableAlias );
1340+ if ($ filterSql ) {
1341+ $ joinCondition [] = $ filterSql ;
1342+ }
13371343 }
13381344
13391345 $ this ->currentPersisterContext ->selectJoinSql .= ' ' . $ joinTableName . ' ' . $ joinTableAlias . ' ON ' ;
Original file line number Diff line number Diff line change @@ -89,17 +89,24 @@ public function __construct(
8989 $ this ->platform = $ query ->getEntityManager ()->getConnection ()->getDatabasePlatform ();
9090 $ this ->rsm = $ parserResult ->getResultSetMapping ();
9191
92- $ query = clone $ query ;
92+ $ cloneQuery = clone $ query ;
93+
94+ $ cloneQuery ->setParameters (clone $ query ->getParameters ());
95+ $ cloneQuery ->setCacheable (false );
96+
97+ foreach ($ query ->getHints () as $ name => $ value ) {
98+ $ cloneQuery ->setHint ($ name , $ value );
99+ }
93100
94101 // Reset limit and offset
95- $ this ->firstResult = $ query ->getFirstResult ();
96- $ this ->maxResults = $ query ->getMaxResults ();
97- $ query ->setFirstResult (0 )->setMaxResults (null );
102+ $ this ->firstResult = $ cloneQuery ->getFirstResult ();
103+ $ this ->maxResults = $ cloneQuery ->getMaxResults ();
104+ $ cloneQuery ->setFirstResult (0 )->setMaxResults (null );
98105
99- $ this ->em = $ query ->getEntityManager ();
106+ $ this ->em = $ cloneQuery ->getEntityManager ();
100107 $ this ->quoteStrategy = $ this ->em ->getConfiguration ()->getQuoteStrategy ();
101108
102- parent ::__construct ($ query , $ parserResult , $ queryComponents );
109+ parent ::__construct ($ cloneQuery , $ parserResult , $ queryComponents );
103110 }
104111
105112 /**
Original file line number Diff line number Diff line change 88use Doctrine \Common \Collections \Collection ;
99use Doctrine \ORM \Mapping as ORM ;
1010use Doctrine \ORM \Query \QueryException ;
11+ use Doctrine \ORM \Tools \Pagination \Paginator ;
1112use Doctrine \Tests \OrmFunctionalTestCase ;
1213
1314use function count ;
15+ use function iterator_to_array ;
1416
1517class EagerFetchCollectionTest extends OrmFunctionalTestCase
1618{
@@ -97,6 +99,16 @@ public function testSubselectFetchJoinWithAllowedWhenOverriddenNotEager(): void
9799 $ this ->assertIsString ($ query ->getSql ());
98100 }
99101
102+ public function testSubselectFetchJoinWithAllowedWhenOverriddenNotEagerPaginator (): void
103+ {
104+ $ query = $ this ->_em ->createQuery ('SELECT o, c FROM ' . EagerFetchOwner::class . ' o JOIN o.children c WITH c.id = 1 ' );
105+ $ query ->setMaxResults (1 );
106+ $ query ->setFetchMode (EagerFetchChild::class, 'owner ' , ORM \ClassMetadata::FETCH_LAZY );
107+
108+ $ paginator = new Paginator ($ query , true );
109+ $ this ->assertIsArray (iterator_to_array ($ paginator ));
110+ }
111+
100112 public function testEagerFetchWithIterable (): void
101113 {
102114 $ this ->createOwnerWithChildren (2 );
Original file line number Diff line number Diff line change @@ -503,6 +503,21 @@ public function testToOneFilter(): void
503503 self ::assertEquals (2 , count ($ query ->getResult ()));
504504 }
505505
506+ public function testOneToOneInverseSideWithFilter (): void
507+ {
508+ $ this ->loadFixtureData ();
509+
510+ $ conf = $ this ->_em ->getConfiguration ();
511+ $ conf ->addFilter ('country ' , '\Doctrine\Tests\ORM\Functional\CMSCountryFilter ' );
512+ $ this ->_em ->getFilters ()->enable ('country ' )->setParameterList ('country ' , ['Germany ' ], Types::STRING );
513+
514+ $ user = $ this ->_em ->find (CmsUser::class, $ this ->userId );
515+ self ::assertNotEmpty ($ user ->address );
516+
517+ $ user2 = $ this ->_em ->find (CmsUser::class, $ this ->userId2 );
518+ self ::assertEmpty ($ user2 ->address );
519+ }
520+
506521 public function testManyToManyFilter (): void
507522 {
508523 $ this ->loadFixtureData ();
Original file line number Diff line number Diff line change 1414
1515final class LimitSubqueryOutputWalkerTest extends PaginationTestCase
1616{
17+ public function testSubqueryClonedCompletely (): void
18+ {
19+ $ query = $ this ->createQuery ('SELECT p FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p ' );
20+ $ query ->setParameter ('dummy-param ' , 123 );
21+ $ query ->setHint ('dummy-hint ' , 'dummy-value ' );
22+ $ query ->setCacheable (true );
23+
24+ $ walker = new LimitSubqueryOutputWalker ($ query , new Query \ParserResult (), []);
25+
26+ self ::assertNotSame ($ query , $ walker ->getQuery ());
27+ self ::assertTrue ($ walker ->getQuery ()->hasHint ('dummy-hint ' ));
28+ self ::assertSame ('dummy-value ' , $ walker ->getQuery ()->getHint ('dummy-hint ' ));
29+ self ::assertNotSame ($ query ->getParameters (), $ walker ->getQuery ()->getParameters ());
30+ self ::assertInstanceOf (Query \Parameter::class, $ param = $ walker ->getQuery ()->getParameter ('dummy-param ' ));
31+ self ::assertSame (123 , $ param ->getValue ());
32+ self ::assertFalse ($ walker ->getQuery ()->isCacheable ());
33+ }
34+
1735 public function testLimitSubquery (): void
1836 {
1937 $ this ->assertQuerySql (
You can’t perform that action at this time.
0 commit comments