我尝试从2个具有多种关系的实体创建一个连接表:
class Entity1
{
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @JoinTable(name="users_orders",
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
private $orders;
}
但每次我尝试生成getter和setter时都会遇到同样的错误:
注释@JoinTable ...从未导入过。您是否忘记为此注释添加use语句?
那么如何添加use语句呢?谢谢你的帮助
答案 0 :(得分:3)
您需要将@ORM\
放在所有Doctrine注释的前面:
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @ORM\JoinTable(name="users_orders",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
private $orders;
答案 1 :(得分:3)
在JoinTable
和JoinColumn
/**
* @ORM\ManyToMany(targetEntity="Orders")
* @ORM\JoinTable(name="users_orders",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="order_id", referencedColumnName="id", unique=true)
*/
并在课程顶部添加'使用' -statement:
use Doctrine\ORM\Mapping as ORM;