ManyToManyPersister fails to remove join table entry if there is multiple join columns#6997
Conversation
Ocramius
left a comment
There was a problem hiding this comment.
Overall good patch. Comments are really just nits, but we may need to check whether removal of the EntityManager#flush() call is possible. This is done elsewhere via UnitOfWork#registerManaged() (which may not even be needed here)
| @@ -0,0 +1,103 @@ | |||
| <?php | |||
| /** | |||
| /** | ||
| * @return int | ||
| */ | ||
| public function getId1(): int { |
There was a problem hiding this comment.
Remove all public API that isn't strictly needed. Use public properties instead
| /** | ||
| * @return int | ||
| */ | ||
| public function getId(): int { |
There was a problem hiding this comment.
Remove all public API that isn't strictly needed
| use Doctrine\ORM\Mapping\JoinColumn; | ||
| use Doctrine\ORM\Mapping\JoinTable; | ||
| /** | ||
| * Class ChildClass |
| use Doctrine\ORM\Mapping\JoinTable; | ||
| /** | ||
| * Class ChildClass | ||
| * @package Doctrine\Tests\Models\ManyToManyPersister |
| @@ -0,0 +1,72 @@ | |||
| <?php | |||
| /** | |||
| @@ -0,0 +1,65 @@ | |||
| <?php | |||
| /** | |||
| $lastUpdate = array_pop($updates); | ||
|
|
||
| $this->assertEquals('DELETE FROM parent_child WHERE child_id1 = ? AND child_id2 = ?', $lastUpdate['query']); | ||
| $this->assertEquals([1,2], $lastUpdate['params']); |
There was a problem hiding this comment.
Consider using fixed assigned identifiers instead of AUTO_INCREMENT to prevent issues with subsequent test runs.
There was a problem hiding this comment.
Errata: I see you are already doing that 👍
| /** @var ConnectionMock $conn */ | ||
| $conn = $this->em->getConnection(); | ||
|
|
||
| $updates = $conn->getExecuteUpdates(); |
There was a problem hiding this comment.
Wondering if a full mock connection would be better here, assuming that we completely get rid of that EntityManager#flush() call
|
Hi @Ocramius, I cleaned the test case as you requested. Howerver, I'm not sure to understand what you want to do with the Best Regards, |
lcobucci
left a comment
There was a problem hiding this comment.
I've just executed your tests without the fix and it passed, this doesn't look like an issue IMO...
|
@lcobucci Yes it looks like the test case is not correct. The original code in $params[] = isset($sourceClass->fieldNames[$refColumnName])
? $identifier[$sourceClass->fieldNames[$refColumnName]]
: $identifier[$sourceClass->getFieldForColumn($columnName)];When I stumble upon this issue, which cannot work as I will investigate further and update the unit test to make it useful. |
|
Test case updated. To actually reproduce the issue, we need :
In this case:
|
|
@NicolaF I will check it in a bit, can you please execute |
|
@lcobucci done |
…has a composite PK
cdd3830 to
40f2a3e
Compare
@Ocramius I've made some minor changes to simplify the SUT and organise the annotations. It LGTM now. The build is failing for nightly PHP and mysql/pgsql but I think this is fine. |
|
@NicolaF 🚢 thanks! |
|
You're welcome! |
This is due to a typo in
\Doctrine\ORM\Persisters\Collection\ManyToManyPersister::getDeleteSQLParameters:It should be
$sourceClass->getFieldForColumn($refColumnName), as$columnNameis the join table column, not the entity table column.