我按照symfony doc here创建了两个班级partgroup(OneToMany)
和partsub(ManyToOne)
之间的双向关系
当我尝试验证学说架构时,我收到此错误消息
* The association Test\MyBundle\Entity\SpareParts\OemPartPosSubText#partgrpidk refers to the inverse side field Test\MyBundle\Entity\SpareParts\OemPartPosGrpText#partgrpidk which is not defined as association.
* The association Test\MyBundle\Entity\SpareParts\OemPartPosSubText#partgrpidk refers to the inverse side field Test\MyBundle\Entity\SpareParts\OemPartPosGrpText#partgrpidk which does not exist.
和
[Mapping] FAIL - The entity-class 'Test\MyBundle\Entity\SpareParts\OemPartPosGrpText' mapping is invalid:
* The association Test\MyBundle\Entity\SpareParts\OemPartPosGrpText#partsubidk refers to the owning side field Test\MyBundle\Entity\SpareParts\OemPartPosSubText#partsubidk which is not defined as association, but as field.
我尝试了cache:clear
我到处查看堆栈持有人和谷歌但找不到任何解决方案。
答案 0 :(得分:0)
您的映射不正确。适当的映射应该是这样的:
/**
* OemPartPosGrpText
*
* @ORM\Table(name="oem_PartPosGrpText")
* @ORM\Entity(repositoryClass="Test\MyBundle\Entity\SpareParts\Repo\SparePartMenuRepository")
*
*/
class OemPartPosGrpText
{
/**
* @var integer
*
* @ORM\Column(name="PartGrpIDK", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $partgrpidk;
/**
* @ORM\OneToMany(targetEntity="partSubText", mappedBy="partgrp")
*/
private $partsubs;
...
/**
* oemPartPosSubText
*
* @ORM\Table(name="oem_PartPosSubText")
* @ORM\Entity(repositoryClass="Test\MyBundle\Entity\SpareParts\Repo\SparePartMenuRepository")
*/
class partSubText
{
/**
* @var integer
*
* @ORM\Column(name="PartSubIDK", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $partsubidk;
/**
* @ORM\ManytoOne(targetEntity="OemPartPosGrpText",inversedBy="partsubs")
* @ORM\JoinColumn(name="PartGrpIDK", referencedColumnName="PartGrpIDK")
*/
private $partgrp;
...
(我也修改了你的属性名称)