fzaninotto/Faker

Loaded entities in column formatter seem to be treated as new entities in 1.9.0

Open

#1,862 建立於 2019年12月2日

在 GitHub 查看
 (12 留言) (2 反應) (0 負責人)PHP (26,685 star) (3,587 fork)batch import
bughelp wanted

描述

Summary

When upgrading from 1.8.0 to 1.9.0, using a collection of existing entities in a column formatter results in an error. It seems that the existing entities are now treated as new entities instead.

This seems to be caused by the addition in PR https://github.com/fzaninotto/Faker/pull/1781: https://github.com/fzaninotto/Faker/commit/c49cd5438655043b487f4d986961746ae58edb3a#diff-d38baf8c465e27d0cc5334cf5d8475aaR105

Versions

Version
PHP 7.3.10
fzaninotto/faker 1.9.0

Self-enclosed code snippet for reproduction

        $populator->addEntity(User::class, 4, [
            'roles' => function () use ($generator) {
                $roles = ['ROLE_CONTRACTOR', 'ROLE_USER', 'ROLE_CONTRACTOR_USER'];
                $key   = array_rand($roles);

                return [$roles[$key]];
            },
            'username' => function () use ($generator) {
                return $generator->unique()->userName().'@example.com';
            },
            'magicLinkToken' => function () use ($generator) {
                return md5('test');
            },
        ]);

        $populator->execute($manager);

        $users = $manager->getRepository(User::class)->findAll();

        $populator->addEntity(Status::class, 50, [
            'user' => function () use ($generator, $users) {
                $key = array_rand($users);

                return $users[$key];
            },
        ]);

        $populator->execute($manager);

Expected output

Actual output

  [Doctrine\DBAL\Driver\PDOException (23000)]
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'fabienne01@example.com' for key 'UNIQ_8D93D649F85E0677'

貢獻者指南