Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Doctrine] Support for disabling ID generators if ID provided in fixt…
…ure - part 2 (#89) When we find an entity with a provided ID, we disable the auto ID generator strategy for the whole class. Unfortunately, an entity can have a provided ID but the next one may not and as a result the persisting will fail because Doctrine expected an ID but none where found. This issue cannot be fixed because the auto ID generation strategy is a configuration done for the whole class and not on an entity basis. So if this happens, we now bail out with an comprehensive message instead of a cryptic one.
- Loading branch information
Showing
4 changed files
with
117 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry\AliceDataFixtures package. | ||
* | ||
* (c) Théo FIDRY <theo.fidry@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fidry\AliceDataFixtures\Bridge\Doctrine\Entity; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class DummyWithIdentifier | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="integer") | ||
* @GeneratedValue | ||
*/ | ||
public $id; | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/Exception/ObjectGeneratorPersisterExceptionFactory.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,33 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry\AliceDataFixtures package. | ||
* | ||
* (c) Théo FIDRY <theo.fidry@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fidry\AliceDataFixtures\Exception; | ||
|
||
use LogicException; | ||
|
||
/** | ||
* @private | ||
*/ | ||
final class ObjectGeneratorPersisterExceptionFactory | ||
{ | ||
|
||
public static function createForEntityMissingAssignedIdForField($entity): LogicException | ||
{ | ||
return new LogicException(sprintf('No ID found for the entity "%1$s". If this entity has an auto ID generator, ' . | ||
'this may be due to having it disabled because one instance of the entity had an ID assigned. ' . | ||
'Either remove this assigned ID to allow the auto ID generator to operate or generate and ID for ' . | ||
'all the "%1$s" entities.', | ||
get_class($entity) | ||
)); | ||
} | ||
} |
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