我怀疑是否有嵌入式表格。我有一个“属性”实体,它有2个字段“id”和“name”和“Amenities”实体,它有2个字段“id”和“value”(id = 1,value = wifi,id = 2,value = water ,id = 3,value = food)。我创建了这两个实体,但现在我想将“Properties”和“Amenities”的id保存到一个单独的3rd表中。所以,我创建了第三个实体“Properties_Amenities”和它的表“properties_amenities”。我创建了“一对多”关系,如下所示。我想通过点击“属性表”中的“添加设施”按钮将“设施”嵌入“属性”.I我不确定在实体文件中放置“addAmenities()”和“removeAmenities()”函数的位置。以下是3个实体: -
Properties.php
<?php
namespace EpitaEvents\FormBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Properties
*
* @ORM\Table(name="properties")
* @ORM\Entity
*/
class Properties
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=100)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity="Properties_Amenities", mappedBy="properties",cascade={"persist"})
**/
private $properties_amenities1;
public function __construct() {
$this->properties_amenities1 = new ArrayCollection();
}
/**
* Get id
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*/
public function getName()
{
return $this->name;
}
/**
* Get properties_amenities1
*/
public function getProperties_Amenities1()
{
return $this->properties_amenities1;
}
/**
* Set properties_amenities1
*
*/
public function setProperties_Amenities1($properties_amenities1)
{
$this->properties_amenities1 = $properties_amenities1;
return $this;
}
/**
* Add Amenities
*
* @return Properties
*/
public function addAmenities(\EpitaEvents\FormBundle\Entity\Properties_Amenities $amenities)
{
$amenities->setProperties($this);
$this->amenities[] = $amenities;
return $this;
}
/**
* Remove Amenities
*
*/
public function removeAmenities(\EpitaEvents\FormBundle\Entity\Properties_Amenities $amenities) {
$this->amenities->removeElement($amenities);
}
}
Amenities.php
<?php
namespace EpitaEvents\FormBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Amenities
*
* @ORM\Table(name="amenities")
* @ORM\Entity
*/
class Amenities
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="value", type="string", length=100)
*/
private $value;
/**
* @ORM\OneToMany(targetEntity="Properties_Amenities", mappedBy="amenities")
**/
private $properties_amenities2;
public function __construct() {
$this->properties_amenities2 = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set value
*
* @param string $value
* @return Amenities
*/
public function setValue($value)
{
$this->value = $value;
return $this;
}
/**
* Get value
*
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* Set Properties
*
*/
public function setProperties_Amenities2($properties_amenities2)
{
$this->properties_amenities2 = $properties_amenities2;
return $this;
}
/**
* Get Properties
*
* @return EpitaEvents\FormBundle\Entity\Properties
*/
public function getProperties_Amenities2()
{
return $this->properties_amenities2;
}
}
(也应将__construct()放入上述2个文件或“Properties_Amenities.php”(下)中) Properties_Amenities.php
<?php
namespace EpitaEvents\FormBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Properties_Amenities
*
* @ORM\Table(name="properties_amenities")
* @ORM\Entity
*/
class Properties_Amenities
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Properties", inversedBy="properties_amenities1")
* @ORM\JoinColumn(name="properties_id", referencedColumnName="id")
**/
private $properties;
/**
* @ORM\ManyToOne(targetEntity="Amenities", inversedBy="properties_amenities2")
* @ORM\JoinColumn(name="amenities_id", referencedColumnName="id")
**/
private $amenities;
function getId() {
return $this->id;
}
function getProperties() {
return $this->properties;
}
function getAmenities() {
return $this->amenities;
}
function setProperties($properties) {
$this->properties = $properties;
}
function setAmenities($amenities) {
$this->amenities = $amenities;
}
}
任何人都可以建议在哪里放置“addAmenities()”和“removeAmenities()”函数,因为我想在“分离”中保存“Properties.php”和“Amenities.php”的“id” ,第三个“实体和表??