fzaninotto/Faker

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

开放

#1,862 创建于 2019年12月2日

 (12 条评论) (2 个反应) (0 位负责人)PHP (3,587 个派生)batch import
bughelp wanted

仓库指标

星标
 (26,685 个星标)
PR 合并指标
 (30 天内没有已合并 PR)

描述

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'

贡献者指南