Search code examples
phpmongodbsymfonydoctrine-ormodm

ReferenceMany doesn't work Doctrine ODM


Hi everyBody i have actually a problem with doctrine (Symfony2 project) so in fact i have a document "Question" which references "$ref" tag which is a tag in the "Category" document but im getting error that i can't understand. i searched in the doctrine documentation but didn't find a solution, here is the code :

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;


/**
  *@MongoDB\Document(repositoryClass="ATS\QuizzBundle\Document\CategoryRepository")
*/

class Category {

/**
 * @MongoDB\Id
*/
protected $id;

/**
 * @MongoDB\String
*/
protected $label;

/**
 *@MongoDB\int
 *@ReferenceMany(targetDocument="Question")
*/
protected $ref ;
}

And i'm getting this error:

  [Semantical Error] The annotation "@MongoDB\Document" in class ATS\QuizzBun  
  dle\Document\Category was never imported. Did you maybe forget to add a "us  
  e" statement for this annotation?

Solution

  • The correct annotation here would be @MongoDB\ReferenceMany.