【发布时间】:2017-10-06 13:13:18
【问题描述】:
我正在尝试在我的新表中插入数据,这是实体代码
<?php
namespace IT\ITBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Famille
* @ORM\Table(name="famille")
* @ORM\Entity(repositoryClass="IT\ITBundle\Repository\FamilleRepository")
*/
class Famille
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="lien", type="string", length=255, nullable=true)
*/
private $lien;
/**
* @ORM\ManyToOne(targetEntity="IT\ITBundle\Entity\Personne", inversedBy="familles")
* @ORM\JoinColumn(nullable=false)
*/
private $personne;
/**
* @ORM\OneToMany(targetEntity="IT\ITBundle\Entity\Famille", mappedBy="personne",cascade={"persist"})
* @ORM\JoinColumn(name="enfant_id", referencedColumnName="id")
*/
private $enfant;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set lien
*
* @param string $lien
* @return Famille
*/
public function setLien($lien)
{
$this->lien = $lien;
return $this;
}
/**
* Get lien
*
* @return string
*/
public function getLien()
{
return $this->lien;
}
/**
* Set personne
*
* @param \IT\ITBundle\Entity\Personne $personne
*
* @return Famille
*/
public function setPersonne(\IT\MITBundle\Entity\PersonnePhysique $personne = null)
{
$this->personne = $personne;
return $this;
}
/**
* Get personne
*
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getPersonne()
{
return $this->personne;
}
/**
* Set enfant
*
* @param PersonnePhysique $personne
*
* @return Famille
*/
public function setEnfant($enfant)
{
$this->enfant = $enfant;
return $this;
}
/**
* Get enfant
*
* @return Personne
*/
public function getEnfant()
{
return $this->enfant;
}
public function __construct()
{
$this->familles = new \Doctrine\Common\Collections\ArrayCollection();
}
}
这是我的第二个实体
/** * @var 集合。 * @ORM\OneToMany(targetEntity="IT\ITBundle\Entity\Famille",cascade={"persist","remove"}, mappedBy="personne")
*/
private $familles;
我的控制器是
public function newAction(Request $request)
{
$controle = $this->get('Controles');
if(($controle->is_Granted('Ajout personne Morale','Client/Societaire',$this->getUser()))==false){throw new AccessDeniedException();}
$personne = new PersonneMorale();
$form = $this->createForm(PersonneMoraleType::class, $personne);
$form->handleRequest($request);
$mails=$personne->getEmails();
if(!empty($mails)){
foreach($mails as $mail){
$mail->setPersonne($personne);
}
}
$adress=$personne->getAdresses();
if(!empty($adress)){
foreach($adress as $adre){
$adre->setPersonne($personne);
}
}
$tels=$personne->getTelecoms();
if(!empty($tels)){
foreach($tels as $tel){
$tel->setPersonne($personne);
}
}
$compteBancaires=$personne->getCompteBancaires();
if(!empty($compteBancaires)){
foreach($compteBancaires as $cmp){
$cmp->setPersonne($personne);
}
}
$contacts=$personne->getContacts();
if(!empty($contacts)){
foreach($contacts as $contact){
$contact->setPersonne($personne);
}
}
$familles=$personne->getfamilles();
if(!empty($familles)){
foreach($familles as $fam){
$fam->setFamille($personne);
}
}
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$maxNum = $em->getRepository('ITBundle:Personne')->getMaxNumPersonne();
if($maxNum == null){
$personne->setNumpersonne(1000000);
}
else{
$personne->setNumpersonne($maxNum+1);
}
$em->persist($personne);
$em->flush();
// return $this->redirectToRoute('Personne_morale_index', array());
return $this->render('ClientsBundle:Morale:success.html.twig', array(
'personne' => $personne
));
}
return $this->render('ClientsBundle:Morale:new.html.twig', array(
'post' => $personne,
'form' => $form->createView()
));
}
如您所见,我只能保存“lien”,但我想保存 personne_id 和 enfant_id enter image description here
【问题讨论】:
-
有什么错误吗?你有什么问题?
-
如您所见,我只能保存“lien”,但我想保存 personne_id 和 enfant_id 在此处输入图像描述
-
请帮忙
-
你更新你的数据库架构了吗???
-
不,我手动完成所有代码。我应该更新数据库 shema 以及我如何做到这一点
标签: javascript php sql symfony