我有兩個實體與這個問題有關,我想要一個連接表能夠在每個表中交叉引用值。Symfony2學說ManyToMany關聯映射無效?
這裏有一個解釋:
實體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中,所以我不明白爲什麼它試圖在容器實體中引用一個名爲container的字段?
任何人都可以對此有所瞭解嗎?
謝謝 邁克爾