Symfony 3关于OneToMany关于genarate:enities的联合表错误

时间:2016-04-27 15:22:30

标签: php doctrine-orm one-to-many symfony

我有以下代码(2个表'广告和城市): 当我运行cmd' php bin / console doctrine:generate:entities MyBundle'生成setter和geters(Symfony3) 出现此错误:

  

[语义错误]注释" @ JoinColumn"在财产   从未导入过Ligo \ PlatformBundle \ Entity \ Advert :: $ cities。你是否   也许忘记添加"使用"这个注释的陈述? 500   内部服务器错误 - AnnotationException


<?php

namespace Ligo\PlatformBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 * Advert
 *
 * @ORM\Table(name="advert")
 * @ORM\Entity(repositoryClass="Ligo\PlatformBundle\Repository\AdvertRepository")
 */
class Advert
{
     /**
     * @ORM\ManyToMany(targetEntity="City")
     * @ORM\JoinTable(name="adverts_cities",
     *      joinColumns={@JoinColumn(name="advert_id", referencedColumnName="id")},
     *      inverseJoinColumns={@JoinColumn(name="city_id", referencedColumnName="id", unique=true)}
     *      )
     */
    private $cities;

1 个答案:

答案 0 :(得分:2)

您需要在JoinColumn注释前加上ORM(@ORM\JoinColumn),因为您没有专门导入它。