3

我正在定义这个夹具:

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 次尝试中的名称。

我通过这个错误对 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;
    }

}
4

1 回答 1

2

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

name (unique): Alias_<numberBetween(1, 1000)>
于 2015-12-22T20:46:49.397 回答