我希望我的电子邮件属性在用户集合中是唯一的。 我尝试了很多方法,但仍然可以插入相同的电子邮件。
这是我的课:
<?php
namespace App\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use Gedmo\Mapping\Annotation as Gedmo;
use JMS\Serializer\Annotation\ExclusionPolicy;
use JMS\Serializer\Annotation\Expose;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique as MongoDBUnique;
/**
* @ODM\Document(
* collection="User",
* repositoryClass="App\Document\Repository\UserRepository"
* )
* @MongoDBUnique(fields={"email"})
* @ExclusionPolicy("all")
*/
abstract class User implements UserInterface, \Serializable
{
/**
* @var ODM\Id $id
* @ODM\Id(strategy="auto")
* @Expose
*/
private $id;
/**
* @ODM\Field(type="string")
* @Assert\NotBlank()
* @Assert\Length(max=60)
* @Assert\Email()
* @ODM\UniqueIndex(order="asc")
* @Expose
*/
private $email;
预先感谢您:)