我的数据库中有3个这样的表:文章:带有idArticle。Fournissor与idFournissor,在他们中间有"Got“谁是由1个PK(idFournissor,idArticle)组成的。
这是一种多对多的关系。此外,我有两个表单: ArticleType和FournissorType,在每个表单中,当我提交时,我的数据库中都有正确的值。然而,对于idArticle中的冠军idFournissor或idFournissor中的idArticle,它可以做任何事情。我解释:例如,文章形式:我必须为我的文章选择一个四分词,所以我选择了其中一个,但实际上在DB中它并没有保存什么东西。
我希望当我提交表单时,在"Got“中有文章id和fournissor的值。
这是我的实体文章,如果它能有所帮助的话:
use Doctrine\ORM\Mapping as ORM; * Article * @ORM\Table(name="Article",indexe{@ORM\Index(name="I_FK_Article_TypeArticle", columns={"idTypeArticle"})}) * @ORM\Entity class Article * @var integer * @ORM\Column(name="idArticle", type="bigint") * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") private $idarticle; * @var string * @ORM\Column(name="reference", type="string", length=35, nullable=true) private $reference; * @var string * @ORM\Column(name="designationFR", type="string", length=160, nullable=true) private $designationfr; * @var string * @ORM\Column(name="designationEN", type="string", length=160, nullable=true) private $designationen; * @var string * @ORM\Column(name="plan", type="string", length=70, nullable=true) private $plan; * @var \DateTime * @ORM\Column(name="dateCreation", type="date", nullable=true) private $datecreation; * @var integer * @ORM\Column(name="idProduit", type="bigint", nullable=true) private $idproduit; * @var integer * @ORM\Column(name="idSousEnsemble", type="bigint", nullable=true) private $idsousensemble; * @var \gkeepBundle\Entity\Typearticle * @ORM\ManyToOne(targetEntity="gkeepBundle\Entity\Typearticle") * @ORM\JoinColumns({ * @ORM\JoinColumn(name="idTypeArticle", referencedColumnName="idTypeArticle") private $idtypearticle; * @var \Doctrine\Common\Collections\Collection * @ORM\ManyToMany(targetEntity="gkeepBundle\Entity\Fournisseur", mappedBy="idarticle") private $idfournisseur; * Constructor public function __construct() $this->idfournisseur = new \Doctrine\Common\Collections\ArrayCollection(); }
实体四元组:
/** * @var \Doctrine\Common\Collections\Collection * @ORM\ManyToMany(targetEntity="gkeepBundle\Entity\Article", inversedBy="idfournisseur", cascade={"persist"}) * @ORM\JoinTable(name="detient", * joinColumns={ * @ORM\JoinColumn(name="idFournisseur", referencedColumnName="idFournisseur") * }, * inverseJoinColumns={ * @ORM\JoinColumn(name="idArticle", referencedColumnName="idArticle") * } private $idarticle;
文章实体:
/** * Add idfournisseur * @param \gkeepBundle\Entity\Fournisseur $idfournisseur * @return Article public function addIdfournisseur(\gkeepBundle\Entity\Fournisseur $idfournisseur) $idfournisseur->set($this); $this->idfournisseur[] = $idfournisseur; return $this; }
Fournisseur实体:
/** * Add idarticle * @param \gkeepBundle\Entity\Article $idarticle * @return Fournisseur public function addIdarticle(\gkeepBundle\Entity\Article $idarticle) $this->idarticle[] = $idarticle; return $this; }
希望我已经说清楚了,如果你不明白,请告诉我。感谢你的预支
上云精选
2核2G云服务器 每月9.33元起,个人开发者专属3年机 低至2.3折
我认为“级联持久化”被忽略了。下面是一个示例:
代理用户可以拥有多个服务,服务可以拥有多个用户。
// It's Agency Entity * @var Service[]|ArrayCollection * @ORM\ManyToMany(targetEntity="Service", inversedBy="agencyUsers", cascade={"persist"}) * @ORM\JoinTable(name="agency_user_services", * joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, * inverseJoinColumns={@ORM\JoinColumn(name="service_id", referencedColumnName="id")} * ) protected $services; * Add services * @param ServiceInterface $services * @return AgencyAdmin public function addService(ServiceInterface $services) $this->services[] = $services; return $this; * Remove services * @param ServiceInterface $services public function removeService(ServiceInterface $services) $this->services->removeElement($services); //It's Service Entity * @var AgencyAdmin[]|ArrayCollection * @ORM\ManyToMany(targetEntity="AgencyAdmin", mappedBy="services") protected $agencyUsers; * Add agencyUsers * @param AgencyAdmin $agencyUsers * @return Service public function addAgencyUser(AgencyAdmin $agencyUsers) $this->agencyUsers[] = $agencyUsers; return $this; * Remove agencyUsers