class Media extends BaseMedia
/**
* @var Specialists
*
* @ORM\ManyToOne(targetEntity="Specialists", inversedBy="images")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="spec", referencedColumnName="id")
* })
*/
private $spec;
class Specialists
/**
* @var Media
*
* @ORM\OneToMany(targetEntity="Application\Sonata\MediaBundle\Entity\Media", mappedBy="spec")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="images", referencedColumnName="id")
* })
*/
private $images;
在php app / console doctrine:schema:验证错误
之后[制图]失败 - 实体级'专家\专家捆绑\实体\专家'映射无效: *协会专家\专家捆绑\实体\专家#图像是指不存在的拥有方字段Application \ Sonata \ MediaBundle \ Entity \ Media#spec。
我很感激答案
答案 0 :(得分:1)
媒体包最初使用XML格式可能您必须通过修改xml配置文件来定义媒体实体映射信息
试试这个,
class Media extends BaseMedia
{
/*
* ....
*/
private $spec;
//others attributes, getters and setters there
// ...
}
然后改变最初位于以下位置的xml配置文件:“src / Application / Sonata / MediaBundle / Resources / config / doctrine / Media.orm.xml” 这看起来像是
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Application\Sonata\MediaBundle\Entity\Media"
table="media__media"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<!-- then you add this -->
<many-to-one field="spec" target-entity="\path-to\Specialists" inversed-by="images">
<join-column name="spec" referenced-column-name="id" />
</many-to-one>
<!-- end -->
</entity>
</doctrine-mapping>
然后尝试更新您的学说架构