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
Fix for #6393 - use field names when extracting identifier fields #6394
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.
Also we need tests 😄
$columnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->platform); | ||
|
||
$where = array(); |
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.
Please use short array syntax
$columnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->platform); | ||
|
||
$where = array(); | ||
$params = array(); |
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.
Please use short array syntax
|
||
$where = array(); | ||
$params = array(); | ||
foreach ($versionedClass->identifier as $idField) { |
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.
Can you extract a method from this code?
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.
Status: Needs work.
/** | ||
* Determains the identifier columns and values for an entity | ||
* | ||
* @param \Doctrine\ORM\Mapping\ClassMetadata $class |
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.
This class is already imported, so please use ClassMetadata
instead FQCN.
* @param array $id | ||
* @return array | ||
*/ | ||
private function determineIdentifierColumnsAndValues($class, array $id) |
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.
Could you please declare the type for $class
argument?
$this->_em->persist($b); | ||
$this->_em->flush(); | ||
|
||
$this->assertEquals(1, $b->getVersion()); |
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.
Please, use assertSame()
instead.
Any chance for getting this in? |
I think this looks fine, but I don't have my laptop atm. Will try merging later today 👍 |
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 went through the patch again and tried applying it locally. There are some major issues that need fixing:
- only the first association column is considered, whereas the
IdentifierFlattener
considered all columns - the association column is not being quoted
- overall, the logic in
determineIdentifierColumnsAndValues
is an identifier lookup, and it should produce a[ $values, $columns, $types]
triplet - The code in
determineIdentifierColumnsAndValues
should be abstracted away, or an existing abstraction should be found. TheIdentifierFlattener
is close to it, but it was designed for the identity map internals, not for column operations.
Hi I've tried a different (and hopefully better) approach for solving #6394 |
$identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity); | ||
|
||
$id = []; | ||
foreach ($this->class->identifier as $idField) { |
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.
This seems like a workaround to me... as @Ocramius said we should rather use field names everywhere.
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.
This doesn't seem possible, because in UnitOfWork::createEntity
it passes the whole $row ($data) into the identifier flattener and the hydration works by passing the association data as columns not as fields, because it must support composite primary keys as assocations where using field name as a single name would not be able to represent two ore more columns.
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.
ACtually the other way around, BasicEntityPersister::update used the wrong identifier representation. See #8384
class DDC6393Test extends \Doctrine\Tests\OrmFunctionalTestCase | ||
{ | ||
|
||
protected function setUp() |
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.
: void
missing
* Test the the version of an entity can be fetched, when the id field and | ||
* the id column are different. | ||
*/ | ||
public function testFetchVersionValueForDifferentIdFieldAndColumn() |
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.
: void
missing
/** | ||
* Test the the version of an entity can be fetched, when the id field and | ||
* the id column are different. | ||
*/ |
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.
Please add @group 6393
$this->_em->persist($b); | ||
$this->_em->flush(); | ||
|
||
$this->assertSame(1, $b->getVersion()); |
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.
self::assert*
is more appropriated since the method is static
*/ | ||
private $version; | ||
|
||
public function __construct($a, $something) |
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.
public function __construct(A $a, string $something)
$this->something = $something; | ||
} | ||
|
||
public function getA() |
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.
Please this method and make the property public
, so that we simplify the entity a bit
return $this->a; | ||
} | ||
|
||
public function getSomething() |
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.
Please this method and make the property public
, so that we simplify the entity a bit
$this->something = $something; | ||
} | ||
|
||
public function getVersion() |
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.
Please this method and make the property public
, so that we simplify the entity a bit
return $this->something; | ||
} | ||
|
||
public function setSomething($something) |
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.
Please this method and simply change the property on the test
… non-object values
…ntifiers for version assignment.
…ntifiers for version assignment.
Fixes #6393