【问题标题】:Doctrine not found entity idDoctrine 未找到实体 id
【发布时间】:2014-01-04 04:58:47
【问题描述】:

我在 Doctrine 2(使用 Symfony2)中映射实体时遇到问题。 Symfony 说错误在 Perfil 实体中,但 Doctrine 部分分析器说错误是 en Funcion 实体。

这是错误(在浏览器上):

列 id 必须映射到类中的字段 AppsManantiales\CommonBundle\Entity\Perfil 因为它被 加入另一个类的列。

但是,在分析器中:

AppsManantiales\CommonBundle\Entity\Funcion:引用的列 name 'id' 必须是目标实体类的主键列 'AppsManantiales\CommonBundle\Entity\Funion'。引用的列 name 'id' 必须是目标实体类的主键列 'AppsManantiales\CommonBundle\Entity\Perfil'。

这是关系:

Perfil 实体,基本上是:

class Perfil implements RoleInterface{

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", length=10)
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $idperfil;

   /**
    * @ORM\ManyToMany(targetEntity="Funcion", mappedBy="perfiles")
    * @ORM\JoinTable(name="perfil_funcion",
    *      joinColumns={@ORM\JoinColumn(name="perfil", referencedColumnName="idperfil")},
    *      inverseJoinColumns={@ORM\JoinColumn(name="funcion", referencedColumnName="idfuncion")}
    *  )
    */
    protected $funciones;

    // More code...
}

Function 实体基本上是:

class Funcion {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", length=11)
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $idfuncion;

    /**
     * @ORM\ManyToMany(targetEntity="Perfil", inversedBy="funciones")
     */
    protected $perfiles;

    // More code...
}

有什么想法吗?谢谢!

【问题讨论】:

    标签: symfony doctrine-orm


    【解决方案1】:

    我认为默认情况下,Doctrine 依赖于实体中的所有主键都由名为$id 的属性表示的约定。两种解决方案:

    • 将主键从 $idperfil$idfuncion 重命名为 $id(我建议这样做);
    • $perfiles 属性的Funcion 对象上显式连接标准:

      * @ORM\JoinTable(name="perfil_function"),
      *     joinColumns={@ORM\JoinColumn(name="funcion", referencedColumnName="idfuncion")},
      *     inverseJoinColumns={@ORM\JoinColumn(name="perfil", referencedColumnName="idperfil")}
      * )
      

    【讨论】:

    • 谢谢,但是添加这些行并且错误仍然存​​在。因此,删除“funcion”实体上的“$perfiles”。不是重要的财产。
    猜你喜欢
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多