-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix id hash of entity with enum as identifier
When an entity have a backed enum as identifier, `UnitOfWork` tries to cast to string when generating the hash of the id. This fix calls `->value` when identifier is a `BackedEnum`. Fixes #10471 Fixes #10334
- Loading branch information
Showing
9 changed files
with
353 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10334; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\JoinColumn; | ||
use Doctrine\ORM\Mapping\ManyToOne; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class GH10334Foo | ||
{ | ||
/** | ||
* @var GH10334FooCollection | ||
* @Id | ||
* @ManyToOne(targetEntity="GH10334FooCollection", inversedBy="foos") | ||
* @JoinColumn(name="foo_collection_id", referencedColumnName="id", nullable = false) | ||
* @GeneratedValue | ||
*/ | ||
protected $collection; | ||
|
||
/** | ||
* @var GH10334ProductTypeId | ||
* @Id | ||
* @Column(type="string", enumType="Doctrine\Tests\Models\GH10334\GH10334ProductTypeId") | ||
*/ | ||
protected $productTypeId; | ||
|
||
public function __construct(GH10334FooCollection $collection, GH10334ProductTypeId $productTypeId) | ||
{ | ||
$this->collection = $collection; | ||
$this->productTypeId = $productTypeId; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/Doctrine/Tests/Models/GH10334/GH10334FooCollection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10334; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\OneToMany; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class GH10334FooCollection | ||
{ | ||
/** | ||
* @var int | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @OneToMany(targetEntity="GH10334Foo", mappedBy="collection", cascade={"persist", "remove"}) | ||
* @var Collection<GH10334Foo> $foos | ||
*/ | ||
private $foos; | ||
|
||
public function __construct() | ||
{ | ||
$this->foos = new ArrayCollection(); | ||
} | ||
|
||
/** | ||
* @return Collection<GH10334Foo> | ||
*/ | ||
public function getFoos(): Collection | ||
{ | ||
return $this->foos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10334; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\GeneratedValue; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\JoinColumn; | ||
use Doctrine\ORM\Mapping\ManyToOne; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class GH10334Product | ||
{ | ||
/** | ||
* @var int | ||
* @Id | ||
* @Column(name="product_id", type="integer") | ||
* @GeneratedValue() | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var string | ||
* @Column(name="name", type="string") | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* @var GH10334ProductType $productType | ||
* @ManyToOne(targetEntity="GH10334ProductType", inversedBy="products") | ||
* @JoinColumn(name="product_type_id", referencedColumnName="id", nullable = false) | ||
*/ | ||
private $productType; | ||
|
||
public function __construct(string $name, GH10334ProductType $productType) | ||
{ | ||
$this->name = $name; | ||
$this->productType = $productType; | ||
} | ||
|
||
public function getProductType(): GH10334ProductType | ||
{ | ||
return $this->productType; | ||
} | ||
|
||
public function setProductType(GH10334ProductType $productType): void | ||
{ | ||
$this->productType = $productType; | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/Doctrine/Tests/Models/GH10334/GH10334ProductType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10334; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\Id; | ||
use Doctrine\ORM\Mapping\OneToMany; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class GH10334ProductType | ||
{ | ||
/** | ||
* @var GH10334ProductTypeId | ||
* @Id | ||
* @Column(type="string", enumType="Doctrine\Tests\Models\GH10334\GH10334ProductTypeId") | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var float | ||
* @Column(type="float") | ||
*/ | ||
private $value; | ||
|
||
/** | ||
* @OneToMany(targetEntity="GH10334Product", mappedBy="productType", cascade={"persist", "remove"}) | ||
* @var Collection $products | ||
*/ | ||
private $products; | ||
|
||
public function __construct(GH10334ProductTypeId $id, float $value) | ||
{ | ||
$this->id = $id; | ||
$this->value = $value; | ||
$this->products = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): GH10334ProductTypeId | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function addProduct(GH10334Product $product): void | ||
{ | ||
$product->setProductType($this); | ||
$this->products->add($product); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Doctrine/Tests/Models/GH10334/GH10334ProductTypeId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\Models\GH10334; | ||
|
||
enum GH10334ProductTypeId: string | ||
{ | ||
case Jean = 'jean'; | ||
case Short = 'short'; | ||
} |
Oops, something went wrong.