2016-06-07 59 views
1

我是Symfony的初学者,我被要求创建包含一些信息的用户实体,使用FOSUser 一切顺利,直到当我试着做下面一行命令MappingException:无法在'UserBundle Entity User#userRoles'中找到目标实体UserBundle Entity userRoles

php/bin console doctrine:schema:update --force

在这一刻,我有以下错误

[学说\ ORM \制图\ MappingException]
在“UserBundle \ Entity \ User#userRoles”中找不到目标实体UserBundle \ Entity \ userRoles。

我试图改变一些注释,但是,因为我真的不知道我在做什么,这并没有真正的工作

这里的实体的片段

<?php 
// src/UserBundle/Entity/User.php 
namespace UserBundle\Entity; 

use FOS\UserBundle\Model\User as BaseUser; 
use Doctrine\ORM\Mapping as ORM; 
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 
use Symfony\Component\Validator\Constraints as Assert; 

/** 
* @ORM\Entity 
* @UniqueEntity(fields="email", message="Email already taken") 
* @UniqueEntity(fields="username", message="Username already taken") 
*/ 
class User extends BaseUser{ 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

// /** 
// * @ORM\Column(type="string", length=255, unique=true) 
// * @Assert\NotBlank() 
// * @Assert\Email() 
// */ 
// protected $email; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="prenom", type="string", length=255) 
    */ 
    private $prenom; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="nom", type="string", length=255) 
    */ 
    private $nom; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="pseudo", type="string", length=255) 
    */ 
    private $pseudo; 

    /** 
    * @var string 
    * 
    * @ORM\Column(name="telephone", type="string", length=10) 
    */ 
    private $telephone; 

// /** 
// * 
// * @ORM\Column(type="string", length=64) 
// */ 
// protected $password; 

    /** 
    * @ORM\ManyToMany(targetEntity="userRoles", inversedBy="user") 
    * @ORM\JoinTable(name="userRoles") 
    * 
    */ 
    private $userRoles; 





    /** 
    * Set prenom 
    * 
    * @param string $prenom 
    * 
    * @return User 
    */ 
    public function setPrenom($prenom) 
    { 
     $this->prenom = $prenom; 

     return $this; 
    } 

    /** 
    * Get prenom 
    * 
    * @return string 
    */ 
    public function getPrenom() 
    { 
     return $this->prenom; 
    } 

    /** 
    * Set nom 
    * 
    * @param string $nom 
    * 
    * @return User 
    */ 
    public function setNom($nom) 
    { 
     $this->nom = $nom; 

     return $this; 
    } 

    /** 
    * Get nom 
    * 
    * @return string 
    */ 
    public function getNom() 
    { 
     return $this->nom; 
    } 

    /** 
    * Set pseudo 
    * 
    * @param string $pseudo 
    * 
    * @return User 
    */ 
    public function setPseudo($pseudo) 
    { 
     $this->pseudo = $pseudo; 

     return $this; 
    } 

    /** 
    * Get pseudo 
    * 
    * @return string 
    */ 
    public function getPseudo() 
    { 
     return $this->pseudo; 
    } 

    /** 
    * Set telephone 
    * 
    * @param string $telephone 
    * 
    * @return User 
    */ 
    public function setTelephone($telephone) 
    { 
     $this->telephone = $telephone; 

     return $this; 
    } 

    /** 
    * Get telephone 
    * 
    * @return string 
    */ 
    public function getTelephone() 
    { 
     return $this->telephone; 
    } 

    /** 
    * Add userRole 
    * 
    * @param \UserBundle\Entity\Role $userRole 
    * 
    * @return User 
    */ 
    public function addUserRole(\UserBundle\Entity\Role $userRole) 
    { 
     $this->userRoles[] = $userRole; 

     return $this; 
    } 

    /** 
    * Remove userRole 
    * 
    * @param \UserBundle\Entity\Role $userRole 
    */ 
    public function removeUserRole(\UserBundle\Entity\Role $userRole) 
    { 
     $this->userRoles->removeElement($userRole); 
    } 

    /** 
    * Get userRoles 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getUserRoles() 
    { 
     return $this->userRoles; 
    } 
} 

这段代码有什么问题?谢谢你在前进

回答

2

好像你有一个错字在注释中,手风琴与 集的setter/getter方法的签名targetEntity不是userRoles类,但UserBundle\Entity\Role类的好像。

所以更改定义如下:

/** 
* @ORM\ManyToMany(targetEntity="UserBundle\Entity\Role", inversedBy="user") 
* @ORM\JoinTable(name="userRoles") 
* 
*/ 
private $userRoles; 

希望这有助于

+0

谢谢,瞬间解决我的问题! – Jaeger