Skip to content

Commit

Permalink
Merge branch '2.11.x' into 3.0.x
Browse files Browse the repository at this point in the history
* 2.11.x:
  Bump PHPStan & Psalm (doctrine#9303)
  Removing list "Lifecycle Events" (doctrine#9243)
  Drop unneeded backslashes
  Fix Hidden fields triggering error when using getSingleScalarResult() (doctrine#8340)
  Findby joined lookup (doctrine#8285)
  • Loading branch information
derrabus committed Dec 31, 2021
2 parents d781779 + 133cc95 commit 4b062a4
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 204 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@
"doctrine/annotations": "^1.13",
"doctrine/coding-standard": "^9.0",
"phpbench/phpbench": "^1.0",
"phpstan/phpstan": "1.2.0",
"phpstan/phpstan": "1.3.0",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "3.6.2",
"symfony/cache": "^4.4 || ^5.4 || ^6.0",
"vimeo/psalm": "4.15.0"
"vimeo/psalm": "4.16.1"
},
"conflict": {
"doctrine/annotations": "<1.13 || >= 2.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/dql-doctrine-query-language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ clauses:
- ``SQRT(q)`` - Return the square-root of q.
- ``SUBSTRING(str, start [, length])`` - Return substring of given
string.
- ``TRIM([LEADING \| TRAILING \| BOTH] ['trchar' FROM] str)`` - Trim
- ``TRIM([LEADING | TRAILING | BOTH] ['trchar' FROM] str)`` - Trim
the string by the given trim char, defaults to whitespaces.
- ``UPPER(str)`` - Return the upper-case of the given string.
- ``DATE_ADD(date, value, unit)`` - Add the given time to a given date.
Expand Down
213 changes: 86 additions & 127 deletions docs/en/reference/events.rst

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/en/reference/working-with-associations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ For each cascade operation that gets activated, Doctrine also
applies that operation to the association, be it single or
collection valued.

.. _persistence-by-reachability:

Persistence by Reachability: Cascade Persist
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ protected function hydrateAllData()
throw new NonUniqueResultException('The query returned multiple rows. Change the query or use a different result function like getScalarResult().');
}

if (count($data[key($data)]) > 1) {
$result = $this->gatherScalarRowData($data[key($data)]);

if (count($result) > 1) {
throw new NonUniqueResultException('The query returned a row containing multiple columns. Change the query or use a different result function like getScalarResult().');
}

$result = $this->gatherScalarRowData($data[key($data)]);

return array_shift($result);
}
}
43 changes: 24 additions & 19 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use function array_values;
use function assert;
use function count;
use function get_class;
use function implode;
use function is_array;
use function is_object;
Expand Down Expand Up @@ -1932,36 +1931,42 @@ private function getValues($value): array
return [$newValue];
}

if (is_object($value) && $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) {
$class = $this->em->getClassMetadata(get_class($value));
if ($class->isIdentifierComposite) {
$newValue = [];

foreach ($class->getIdentifierValues($value) as $innerValue) {
$newValue = array_merge($newValue, $this->getValues($innerValue));
}

return $newValue;
}
}

return [$this->getIndividualValue($value)];
return $this->getIndividualValue($value);
}

/**
* Retrieves an individual parameter value.
*
* @param mixed $value
*
* @return mixed
* @return array<mixed>
* @psalm-return list<mixed>
*/
private function getIndividualValue($value)
{
if (! is_object($value) || ! $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) {
return $value;
if (! is_object($value)) {
return [$value];
}

$valueClass = ClassUtils::getClass($value);

if ($this->em->getMetadataFactory()->isTransient($valueClass)) {
return [$value];
}

$class = $this->em->getClassMetadata($valueClass);

if ($class->isIdentifierComposite) {
$newValue = [];

foreach ($class->getIdentifierValues($value) as $innerValue) {
$newValue = array_merge($newValue, $this->getValues($innerValue));
}

return $newValue;
}

return $this->em->getUnitOfWork()->getSingleIdentifierValue($value);
return [$this->em->getUnitOfWork()->getSingleIdentifierValue($value)];
}

/**
Expand Down
11 changes: 3 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="v4.15.0@a1b5e489e6fcebe40cb804793d964e99fc347820">
<files psalm-version="4.16.1@aa7e400908833b10c0333861f86cd48c510b60eb">
<file src="lib/Doctrine/ORM/AbstractQuery.php">
<DeprecatedMethod occurrences="3">
<code>getResultCacheDriver</code>
Expand Down Expand Up @@ -3073,17 +3073,12 @@
<RedundantConditionGivenDocblockType occurrences="1"/>
</file>
<file src="lib/Doctrine/ORM/Tools/SchemaTool.php">
<DocblockTypeContradiction occurrences="2">
<code>! $definingClass</code>
<code>$definingClass</code>
</DocblockTypeContradiction>
<MissingClosureParamType occurrences="1">
<code>$asset</code>
</MissingClosureParamType>
<PossiblyNullArrayAccess occurrences="2">
<code>$definingClass</code>
<PossiblyNullArgument occurrences="1">
<code>$referencedFieldName</code>
</PossiblyNullArrayAccess>
</PossiblyNullArgument>
<PossiblyNullReference occurrences="1">
<code>getColumns</code>
</PossiblyNullReference>
Expand Down
97 changes: 97 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/GH7512Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorMap;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\OneToMany;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH7512Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$this->setUpEntitySchema([
GH7512EntityA::class,
GH7512EntityB::class,
GH7512EntityC::class,
]);

$this->_em->persist(new GH7512EntityA());
$this->_em->persist(new GH7512EntityC());
$this->_em->flush();
$this->_em->clear();
}

public function testFindEntityByAssociationPropertyJoinedChildWithClearMetadata(): void
{
// unset metadata for entity B as though it hasn't been touched yet in application lifecycle.
$this->_em->getMetadataFactory()->setMetadataFor(GH7512EntityB::class, null);
$result = $this->_em->getRepository(GH7512EntityC::class)->findBy([
'entityA' => new GH7512EntityB(),
]);
$this->assertEmpty($result);
}
}

/**
* @Entity()
* @InheritanceType("JOINED")
* @DiscriminatorMap({
* "entitya"=Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityA::class,
* "entityB"=Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityB::class
* })
*/
class GH7512EntityA
{
/**
* @Column(type="integer")
* @Id()
* @GeneratedValue(strategy="AUTO")
* @var int
*/
public $id;

/**
* @OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityC", mappedBy="entityA")
* @var Collection<int, GH7512EntityC>
*/
public $entityCs;
}

/**
* @Entity()
*/
class GH7512EntityB extends GH7512EntityA
{
}

/**
* @Entity()
*/
class GH7512EntityC
{
/**
* @Column(type="integer")
* @Id()
* @GeneratedValue(strategy="AUTO")
* @var int
*/
public $id;

/**
* @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\GH7512EntityA", inversedBy="entityCs")
* @var GH7512EntityA
*/
public $entityA;
}
Loading

0 comments on commit 4b062a4

Please sign in to comment.