Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use statement for @OneToOne - Doctrine2

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?

like image 734
Faery Avatar asked Aug 08 '12 07:08

Faery


1 Answers

I think you were meant to use @ORM\OneToOne instead...

/**
 * @ORM\OneToOne(targetEntity="Productss")
 * @ORM\JoinColumn(name="products_id", referencedColumnName="id")
 */
private $products; 
//... 
}
like image 93
JamesHalsall Avatar answered Oct 24 '22 16:10

JamesHalsall