2013-02-25 47 views
9

Sono nuovo in Symfony2 in generale. Questo problema riguarda Doctrine e FOSUserBundle.Symfony2 - Doctrine e FOSUserBundle - annotazioni errate

Ho il seguente Utente.php Entity creato basato su FOSUserBundle e un autore-riferimento molti-a molti.

<?php 

namespace Pan100\MoodLogBundle\Entity; 

use FOS\UserBundle\Entity\User as BaseUser; 
use Doctrine\ORM\Mapping as ORM; 

    /** 
* @ORM\Entity 
* @ORM\Table(name="fos_user") 
*/ 
class User extends BaseUser 
{ 
/** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 


/** 
* @ManyToMany(targetEntity="User", mappedBy="hasAccessToMe") 
**/ 
protected $hasAccessTo; 

/** 
* @ManyToMany(targetEntity="User", inversedBy="hasAccessTo") 
* @JoinTable(name="access", 
*  joinColumns={@JoinColumn(name="id", referencedColumnName="id")}, 
*  inverseJoinColumns={@JoinColumn(name="accessor_id", referencedColumnName="id")} 
*  ) 
**/ 
private $hasAccessToMe;  

public function __construct() 
{ 
    parent::__construct(); 
     $this->hasAccessTo = new \Doctrine\Common\Collections\ArrayCollection(); 
     $this->hasAccessToMe = new \Doctrine\Common\Collections\ArrayCollection(); 
} 
} 

mi dà il seguente errore durante il tentativo di aggiornare la cache o eliminare:

[Doctrine\Common\Annotations\AnnotationException]       
[Semantical Error] The annotation "@ManyToMany" in property Pan100\MoodLog 
Bundle\Entity\User::$hasAccessTo was never imported. Did you maybe forget 
to add a "use" statement for this annotation? 

Cosa c'è di sbagliato qui? E che cos'è una "dichiarazione d'uso"?

risposta

42

Hai dimenticato di aggiungere il prefisso @ORM\ nelle vostre annotazioni:

/** 
* @ManyToMany(targetEntity="User", mappedBy="hasAccessToMe") 
**/ 

dovrebbe essere

/** 
* @ORM\ManyToMany(targetEntity="User", mappedBy="hasAccessToMe") 
**/ 
+1

successo! dal momento che lo uso come ORM devo mettere ORM \ davanti a tutte le annotazioni. – Piddien

3

si potrebbe anche importare ciascuna annotazione individualmente - il modo che preferisco:

use Doctrine\ORM\Mapping\Entity; 
use Doctrine\ORM\Mapping\ManyToMany; 
// ... 

/** 
* @Entity 
*/ 
class User 
{ 
    /** 
    * @ManyToMany(targetEntity="Thing") 
    */ 
    private $things; 

    // ... 
} 
Problemi correlati