-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ManyToManyPersister fails to remove join table entry if there is multiple join columns #6997
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be dropped
/** | ||
* @return int | ||
*/ | ||
public function getId1(): int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all public API that isn't strictly needed
use Doctrine\ORM\Mapping\JoinColumn; | ||
use Doctrine\ORM\Mapping\JoinTable; | ||
/** | ||
* Class ChildClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
use Doctrine\ORM\Mapping\JoinTable; | ||
/** | ||
* Class ChildClass | ||
* @package Doctrine\Tests\Models\ManyToManyPersister |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
@@ -0,0 +1,72 @@ | |||
<?php | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed
@@ -0,0 +1,65 @@ | |||
<?php | |||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be removed
$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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using fixed assigned identifiers instead of AUTO_INCREMENT
to prevent issues with subsequent test runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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$columnName
is the join table column, not the entity table column.