15
我有一个产品表和另一个表与Notes。每个产品可以有或没有一些笔记。我只需要笔记就可以知道他们的产品,但产品不知道它的笔记。我认为,这应该是我的代码:使用语句@OneToOne - Doctrine2
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;
// ...
}
,但它给出了一个错误:[主义\ COMMON \注解\ AnnotationException]
[语义错误]物业EM注释 “@OneToOne” \ MyBundle \ Entity \ Notes :: $产品从未导入。你有没有忘记为这个注释添加“使用 ”声明?
你能帮我解决这个问题吗?
非常感谢您!它正在工作! :) – Faery 2012-08-08 07:32:14
由于文档的原因,出现这种问题的原因是:OneToMany,oneToOne或manyToMany。我有同样的问题只是复制/粘贴官方文档:http://docs.doctrine-project.org/en/latest/reference/association-mapping.html – 2013-02-10 20:23:48
这将是因为教条文档假设你会使用每个'@'类,所以所有注释都使用实际的类名('使用Doctrine/ORM/Mapping/OneToOne' =>'@ OneToOne'),Symfony建议使用Doctrine \ ORM \ Mapping AS ORM'命名空间方法,所有注释都使用ORM作为基础('@ORM \ OneToOne')。 – qooplmao 2014-02-16 01:36:05