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

时间:2015-12-21 19:52:28

标签: php symfony fixtures nelmio-alice alice-fixtures

我正在定义这个装置:

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

我在控制台收到此错误:

  

[RuntimeException的]     无法为Clanmovil \ PlatformBundle \ Entity \ Alias:128次尝试生成随机唯一值。

我对捆绑源上的错误进行了一些研究,但我不清楚问题是什么。这有什么不对?当我发现像这样的问题时,我该怎么做?

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

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;
    }

}

1 个答案:

答案 0 :(得分:2)

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

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