Skip to content
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 ID generation of foreign keys #7054

Merged
merged 3 commits into from
Feb 25, 2018
Merged

Fix ID generation of foreign keys #7054

merged 3 commits into from
Feb 25, 2018

Conversation

cb8
Copy link

@cb8 cb8 commented Feb 9, 2018

this patch is an alternate approach to #7003 which tries to fix #7002. however, it applies to the master branch. so far, i didn't clean up my test cases. in case this patch will get merged despite/instead of #7003, i will push them for review.

@lcobucci
Copy link
Member

@cb8 thanks for your patch, we just merged in the fix for 2.6 and were porting it to master. I'll check your changes to see if it works better for the new version of the code.

@lcobucci lcobucci self-requested a review February 20, 2018 07:21
@lcobucci
Copy link
Member

@cb8 your changeset makes the tests of #6701 pass but breaks SecondLevelCacheCompositePrimaryKeyWithAssociationsTest because it tries to update a read only entity, I'll investigate further this week but it would be nice if you could check it as well.

@cb8
Copy link
Author

cb8 commented Feb 24, 2018

thank you for the review. the deferred IDs were inadvertently flattened when they were added to the original data of the entity. as far as i could see, the failing tests on Travis are not caused by the patch (but don't hold me to that ;)).

Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes, I'll take care of these in a bit. @cb8 thanks a lot for your help!

/** @var LocalColumnMetadata[] $generatedProperties */
$generatedProperties = [];
/** @var ValueGenerationExecutor[] */
$executors = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could extract the generation of this variable to a private method, it would make things more readable

use Doctrine\ORM\Mapping\LocalColumnMetadata;
use Doctrine\ORM\Sequencing\Generator;

class AssocationValueGeneratorExecutor implements ValueGenerationExecutor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here

- class AssocationValueGeneratorExecutor
+ class AssociationValueGeneratorExecutor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class could be final, we definitely don't want people inheriting from it


class AssocationValueGeneratorExecutor implements ValueGenerationExecutor
{
public function execute(EntityManagerInterface $entityManager, /*object*/ $entity) : array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we use PHP 7.2 we can use object as type... I've fixed the interface in #7092


$this->entityIdentifiers[$oid] = $id;
$this->entityIdentifiers[$oid] = $this->em->getIdentifierFlattener()->flattenIdentifier($class, $id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guilhermeblanco this looks ok, but I'd like your eyes here

vhenzl and others added 3 commits February 25, 2018 19:19
When setting deferred ID values, the original data should contain
complete objects (as it would with non-deferred IDs).
@lcobucci lcobucci added this to the 3.0 milestone Feb 25, 2018
@lcobucci lcobucci self-assigned this Feb 25, 2018
@lcobucci lcobucci added the Bug label Feb 25, 2018
@lcobucci lcobucci merged commit 91acb40 into doctrine:master Feb 25, 2018
@lcobucci
Copy link
Member

@cb8 🚢 thanks for your contribution!

@cb8 cb8 deleted the foreign-id branch February 26, 2018 17:03
@greg0ire greg0ire removed this from the 3.0.0 milestone Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flush new entity with relation when use relation in composite key throws ORMInvalidArgumentException
5 participants