Use statement for @OneToOne - Doctrine2
doctrine-orm, php, symfony
Solution
I think you were meant to use `@ORM\OneToOne` instead...
/**
* @ORM\OneToOne(targetEntity="Productss")
* @ORM\JoinColumn(name="products_id", referencedColumnName="id")
*/
private $products;
//...
}
Problem
I have a table with Products and another table with Notes. Each product can have or not some notes. I need only the notes to know to which product they are reffered, but the product not to know about its notes. I think that this should be my code: ``` namespace EM\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM; use EM\MyBundle\Entity\Productss; /** * @ORM\Entity * @ORM\Table(name="notes") */ class Notess { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @OneToOne(targetEntity="Productss") * @JoinColumn(name="products_id", referencedColumnName="id") **/ private $products; //... } namespace EM\MyBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * @ORM\Entity * @ORM\Table(name="domains") */ class Domains { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; // ... } ``` but it gives an error: [Doctrine\Common\Annotations\AnnotationException] [Semantical Error] The annotation "@OneToOne" in property EM\MyBundle\ Entity\Notes::$products was never imported. Did you maybe forget to add a "use " statement for this annotation? Can you please help me to fix this?