Symfony3 学说2 ManyToMany在表中没有添加数据库,其中只有2 PK



我的数据库中有 3 个表,如下所示:文章:带有 idArticle。 Fournissor with idFournissor 在中间有"Got",由 1 PK(idFournissor, idArticle(组成。

这是一种多对多的关系。此外,我有 2 种形式:ArticleType 和 FournissorType,当我提交时,在每种形式中,我的数据库中都有正确的值。 但是,对于idArticle中的冠军idFournissor或idFournissor中的idArticle,它正在做任何事情。我解释:例如,文章形式:我必须为我的文章选择一个 fournissor,所以我选择其中之一,但实际上在数据库中它并没有保存一些东西。

我希望当我提交表格时,"得到"文章中有文章和 fournissor 的 id 的值。

这是我的实体文章,如果可以提供帮助:

use DoctrineORMMapping as ORM;
/**
* Article
*
* @ORMTable(name="Article",indexe{@ORMIndex(name="I_FK_Article_TypeArticle", columns={"idTypeArticle"})})
* @ORMEntity
*/
class Article
{
/**
* @var integer
*
* @ORMColumn(name="idArticle", type="bigint")
* @ORMId
* @ORMGeneratedValue(strategy="IDENTITY")
*/
private $idarticle;
/**
* @var string
*
* @ORMColumn(name="reference", type="string", length=35, nullable=true)
*/
private $reference;
/**
* @var string
*
* @ORMColumn(name="designationFR", type="string", length=160, nullable=true)
*/
private $designationfr;
/**
* @var string
*
* @ORMColumn(name="designationEN", type="string", length=160, nullable=true)
*/
private $designationen;
/**
* @var string
*
* @ORMColumn(name="plan", type="string", length=70, nullable=true)
*/
private $plan;
/**
* @var DateTime
*
* @ORMColumn(name="dateCreation", type="date", nullable=true)
*/
private $datecreation;
/**
* @var integer
*
* @ORMColumn(name="idProduit", type="bigint", nullable=true)
*/
private $idproduit;
/**
* @var integer
*
* @ORMColumn(name="idSousEnsemble", type="bigint", nullable=true)
*/
private $idsousensemble;
/**
* @var gkeepBundleEntityTypearticle
*
* @ORMManyToOne(targetEntity="gkeepBundleEntityTypearticle")
* @ORMJoinColumns({
*   @ORMJoinColumn(name="idTypeArticle", referencedColumnName="idTypeArticle")
* })
*/
private $idtypearticle;
/**
* @var DoctrineCommonCollectionsCollection
*
* @ORMManyToMany(targetEntity="gkeepBundleEntityFournisseur", mappedBy="idarticle")
*/
private $idfournisseur;
/**
* Constructor
*/
public function __construct()
{
$this->idfournisseur = new DoctrineCommonCollectionsArrayCollection();
}

实体 Fournisseur :

/**
* @var DoctrineCommonCollectionsCollection
*
* @ORMManyToMany(targetEntity="gkeepBundleEntityArticle", inversedBy="idfournisseur", cascade={"persist"})
* @ORMJoinTable(name="detient",
*   joinColumns={
*     @ORMJoinColumn(name="idFournisseur", referencedColumnName="idFournisseur")
*   },
*   inverseJoinColumns={
*     @ORMJoinColumn(name="idArticle", referencedColumnName="idArticle")
*   }
* )
*/
private $idarticle;

文章实体 :

/**
* Add idfournisseur
*
* @param gkeepBundleEntityFournisseur $idfournisseur
*
* @return Article
*/
public function addIdfournisseur(gkeepBundleEntityFournisseur $idfournisseur)
{
$idfournisseur->set($this);
$this->idfournisseur[] = $idfournisseur;
return $this;
}

Fournisseur entity :

/**
* Add idarticle
*
* @param gkeepBundleEntityArticle $idarticle
*
* @return Fournisseur
*/
public function addIdarticle(gkeepBundleEntityArticle $idarticle)
{
$this->idarticle[] = $idarticle;
return $this;
}

希望我已经说清楚了,如果你不明白,告诉我。 感谢您的提前

我认为"级联持久性"被遗漏了。这是一个扩展:

代理用户可以有许多服务,也可以服务可以有很多用户。

// It's Agency Entity
/**
* @var Service[]|ArrayCollection
*
* @ORMManyToMany(targetEntity="Service", inversedBy="agencyUsers", cascade={"persist"})
* @ORMJoinTable(name="agency_user_services",
*      joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
*      inverseJoinColumns={@ORMJoinColumn(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
* @ORMManyToMany(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
*
* @param AgencyAdmin $agencyUsers
*/
public function removeAgencyUser(AgencyAdmin $agencyUsers)
{
$this->agencyUsers->removeElement($agencyUsers);
}

最新更新