0

实体\识别

/**
 * @ORM\Entity
 * @ORM\Table(name="c_rcgntn")
 */
class Recognition {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="id")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\RecognitionType", inversedBy="id")
     * @ORM\JoinColumn(name="fk_recogtype_id", referencedColumnName="id")
     */
    protected $recogType;

实体\识别类型

/**
 * @ORM\Entity
 * @ORM\Table(name="c_rcgntn_type")
 */
class RecognitionType {
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Recognition",mappedBy="recogType")
     */
    protected $id;

在我的开发环境中运行它时,我看到错误出现在我的分析器中。这不是一个大问题,因为代码仍在运行并正确返回连接。我只是无法摆脱错误。

关联Entity\Recognition#recogType 是指未定义为关联的逆侧字段Entity\RecognitionType#id。关联Entity\Recognition#recogType是指不存在的反边字段Entity\RecognitionType#id。

4

1 回答 1

0

您将 RecognitionType 中“id”字段的定义Recognition实体的关系混合在一起。从RecognitionType删除行:

@ORM\OneToMany(targetEntity="AppBundle\Entity\Recognition",mappedBy="recogType")

这对于单向关系应该足够了,您对recogType字段的定义就足够了。

如果您还想在 RecognitionType 中添加关系,则向其中添加一个新字段:

/**
 * ORM\OneToMany(targetEntity="AppBundle\Entity\Recognition", mappedBy="recogType")
 */
protected $recognition;

请注意,在上述定义之后不需要模式更新。

于 2018-02-12T16:26:36.093 回答