【发布时间】:2015-10-16 14:20:19
【问题描述】:
我有两个与此问题相关的实体,我希望连接表能够交叉引用每个表中的值。
这里有一个解释:
实体ContainerType.php:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\Containers;
/**
* ContainerType
*
* @ORM\Table(name="container_type")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
*/
class ContainerType
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255)
*/
private $type;
/**
* @var \DateTime
*
* @ORM\Column(name="date_added", type="datetime")
*/
private $dateAdded;
/**
* @var \DateTime
*
* @ORM\Column(name="date_modified", type="datetime", nullable=true)
*/
private $dateModified;
/**
* @ORM\ManyToMany(targetEntity="Containers", inversedBy="type")
* @ORM\JoinTable(name="container_type_containers")
**/
private $container;
public function __construct()
{
$this->container = new ArrayCollection();
}
和实体Containers.php:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\ContainerType;
/**
* Containers
*
* @ORM\Table(name="containers")
* @ORM\Entity
*/
class Containers
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="number", type="string", length=255)
*/
private $number;
/**
* @ORM\ManyToMany(targetEntity="Containers", mappedBy="container")
*/
private $type;
public function __construct()
{
$this->type = new ArrayCollection();
}
虽然架构更新工作没有问题,但当我执行教义:架构:验证时,我得到以下失败:
[Mapping] FAIL - The entity-class 'AppBundle\Entity\Containers' mapping is invalid:
* The association AppBundle\Entity\Containers#type refers to the owning side field AppBundle\Entity\Containers#container which does not exist.
但是 $container 字段确实存在于 ContainerType 中,所以我不明白为什么它试图在 Containers 实体中引用名为 container 的字段?
任何人都可以对此有所了解吗?
谢谢 迈克尔
【问题讨论】:
标签: symfony doctrine-orm mapping entity