php - 无法在 128 次尝试中为 "value"生成随机唯一值

标签 php symfony fixtures nelmio-alice alice-fixtures

我正在定义这个 fixture :

Clanmovil\PlatformBundle\Entity\Alias:
    alias_{1..500}:
        name (unique): Alias_<numberBetween(1, 500)>
        description: <text(150)>
        active: <boolean(31)>
        createdAt: <dateTimeThisYear()>
        updatedAt: <dateTimeThisYear()>

我在控制台收到这个错误:

[RuntimeException] Couldn't generate random unique value for Clanmovil\PlatformBundle\Entity\Alias: name in 128 tries.

我通过 bundle 源上的这个错误做了一些研究,但我不清楚问题可能是什么。这里有什么问题?发现此类问题时我该如何处理?

如果这有帮助,这就是实体的样子:

namespace Clanmovil\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Clanmovil\PlatformBundle\Model\IdentifierAutogeneratedTrait;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Timestampable\Traits\TimestampableEntity;

/**
 * @ORM\Entity
 * @ORM\Table(name="cm_alias",
 *      uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})},
        indexes={@ORM\Index(name="fulltext_idx",
            columns={"name"},
            flags={"fulltext"})})
 * )
 */
class Alias
{
    use IdentifierAutogeneratedTrait;
    use TimestampableEntity;

    /**
     * @var string
     * @ORM\Column(type="string", length=150)
     * @Assert\NotBlank()
     */
    protected $name;

    /**
     * @var string
     * @ORM\Column(type="text", nullable=true)
     */
    protected $description;

    /**
     * @var bool
     * @ORM\Column(type="boolean")
     */
    protected $active = true;

    /**
     * @ORM\ManyToMany(targetEntity="Command", mappedBy="command_alias", cascade={"persist"})
     */
    protected $alias_command;


    /**
     * Set name.
     *
     * @param string $name
     * @return Alias
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name.
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set description.
     *
     * @param string $description
     *
     * @return Alias
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description.
     *
     * @return string
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set active.
     *
     * @param bool $active
     *
     * @return Category
     */
    public function setActive($active)
    {
        $this->active = $active;

        return $this;
    }

    /**
     * Get active.
     *
     * @return bool
     */
    public function getActive()
    {
        return $this->active;
    }

    /**
     * Get command for alias
     *
     * @return string
     */
    public function getAliasCommand()
    {
        return $this->alias_command;
    }

    public function __toString()
    {
        return $this->name;
    }

}

最佳答案

我不知道这是否是最好的解决方案,但到目前为止,我通过增加随机数的数量解决了这个问题:

name (unique): Alias_<numberBetween(1, 1000)>

关于php - 无法在 128 次尝试中为 "value"生成随机唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403331/

相关文章:

php - 找不到目标实体 - MappingException

ruby-on-rails - Rails fixtures 魔法柱不再起作用

python - 我如何在相同的场景中使用相同的步骤,但在 pytest-bdd 中使用不同的参数?

php - 价格过滤分组算法

php - 使用 Xcode 6 和 PHP 文件将图像上传到服务器

php - UTF-8 问题,不知道

symfony - 构建一个表单来处理从 Doctrine Loggable 扩展中恢复的实体

php - Mysql 查询依赖于另一个查询与连接

Php规范。当 mock 必须返回一个对象时调用非对象的成员函数

pytest-parallel 不遵守模块范围的固定装置