File tree 6 files changed +68
-9
lines changed
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:
85
85
namespace VehicleCatalogue\Model;
86
86
87
87
// $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] );
89
89
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 ";
91
91
$audi = $em->createQuery($dql)
92
- ->setParameter(1, ["name" => "Audi A8", "year" => 2010])
92
+ ->setParameter(1, "Audi A8")
93
+ ->setParameter(2, 2010)
93
94
->getSingleResult();
94
95
95
96
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
1334
1334
$ joinCondition [] = $ this ->getSQLTableAlias ($ association ->sourceEntity , $ assocAlias ) . '. ' . $ sourceCol . ' = '
1335
1335
. $ this ->getSQLTableAlias ($ association ->targetEntity ) . '. ' . $ targetCol ;
1336
1336
}
1337
+
1338
+ // Add filter SQL
1339
+ $ filterSql = $ this ->generateFilterConditionSQL ($ eagerEntity , $ joinTableAlias );
1340
+ if ($ filterSql ) {
1341
+ $ joinCondition [] = $ filterSql ;
1342
+ }
1337
1343
}
1338
1344
1339
1345
$ this ->currentPersisterContext ->selectJoinSql .= ' ' . $ joinTableName . ' ' . $ joinTableAlias . ' ON ' ;
Original file line number Diff line number Diff line change @@ -89,17 +89,24 @@ public function __construct(
89
89
$ this ->platform = $ query ->getEntityManager ()->getConnection ()->getDatabasePlatform ();
90
90
$ this ->rsm = $ parserResult ->getResultSetMapping ();
91
91
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
+ }
93
100
94
101
// 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 );
98
105
99
- $ this ->em = $ query ->getEntityManager ();
106
+ $ this ->em = $ cloneQuery ->getEntityManager ();
100
107
$ this ->quoteStrategy = $ this ->em ->getConfiguration ()->getQuoteStrategy ();
101
108
102
- parent ::__construct ($ query , $ parserResult , $ queryComponents );
109
+ parent ::__construct ($ cloneQuery , $ parserResult , $ queryComponents );
103
110
}
104
111
105
112
/**
Original file line number Diff line number Diff line change 8
8
use Doctrine \Common \Collections \Collection ;
9
9
use Doctrine \ORM \Mapping as ORM ;
10
10
use Doctrine \ORM \Query \QueryException ;
11
+ use Doctrine \ORM \Tools \Pagination \Paginator ;
11
12
use Doctrine \Tests \OrmFunctionalTestCase ;
12
13
13
14
use function count ;
15
+ use function iterator_to_array ;
14
16
15
17
class EagerFetchCollectionTest extends OrmFunctionalTestCase
16
18
{
@@ -97,6 +99,16 @@ public function testSubselectFetchJoinWithAllowedWhenOverriddenNotEager(): void
97
99
$ this ->assertIsString ($ query ->getSql ());
98
100
}
99
101
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
+
100
112
public function testEagerFetchWithIterable (): void
101
113
{
102
114
$ this ->createOwnerWithChildren (2 );
Original file line number Diff line number Diff line change @@ -503,6 +503,21 @@ public function testToOneFilter(): void
503
503
self ::assertEquals (2 , count ($ query ->getResult ()));
504
504
}
505
505
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
+
506
521
public function testManyToManyFilter (): void
507
522
{
508
523
$ this ->loadFixtureData ();
Original file line number Diff line number Diff line change 14
14
15
15
final class LimitSubqueryOutputWalkerTest extends PaginationTestCase
16
16
{
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
+
17
35
public function testLimitSubquery (): void
18
36
{
19
37
$ this ->assertQuerySql (
You can’t perform that action at this time.
0 commit comments