1

I did my database using Wampserver and for the relations i used the casdace and i did the reverse engeenering so ..i can't delete a related object

this is my entities

1rst :

/**
 * Voiture
 *
 * @ORM\Table(name="voiture")
 * @ORM\Entity
 */
class Voiture
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id_voiture", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    public $idVoiture;

    /**
     * @var string
     *
     * @ORM\Column(name="immatricule", type="string", length=50, nullable=false)
     */
    private $immatricule;

    /**
     * @var string
     *
     * @ORM\Column(name="marque", type="string", length=20, nullable=false)
     */
    private $marque;

    /**
     * @var string
     *
     * @ORM\Column(name="modele", type="string", length=20, nullable=false)
     */
    private $modele;

    /**
     * @var string
     *
     * @ORM\Column(name="typecarburant", type="string", length=20, nullable=false)
     */
    private $typecarburant;

    /**
     * @var integer
     *
     * @ORM\Column(name="nbcheveaux", type="integer", nullable=false)
     */
    private $nbcheveaux;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="datemarche", type="date", nullable=false)
     */
    private $datemarche;

    /**
     * @var integer
     *
     * @ORM\Column(name="nbr_place", type="integer", nullable=false)
     */
    private $nbrPlace;

    /**
     * @var integer
     *
     * @ORM\Column(name="id_user", type="integer", nullable=true)
     */
    private $idUser;

    /**
     * @return int
     */
    public function getIdVoiture()
    {
        return $this->idVoiture;
    }

    /**
     * @param int $idVoiture
     */
    public function setIdVoiture($idVoiture)
    {
        $this->idVoiture = $idVoiture;
    }

    /**
     * @return string
     */
    public function getImmatricule()
    {
        return $this->immatricule;
    }

    /**
     * @param string $immatricule
     */
    public function setImmatricule($immatricule)
    {
        $this->immatricule = $immatricule;
    }

    /**
     * @return string
     */
    public function getMarque()
    {
        return $this->marque;
    }

    /**
     * @param string $marque
     */
    public function setMarque($marque)
    {
        $this->marque = $marque;
    }

    /**
     * @return string
     */
    public function getModele()
    {
        return $this->modele;
    }

    /**
     * @param string $modele
     */
    public function setModele($modele)
    {
        $this->modele = $modele;
    }

    /**
     * @return string
     */
    public function getTypecarburant()
    {
        return $this->typecarburant;
    }

    /**
     * @param string $typecarburant
     */
    public function setTypecarburant($typecarburant)
    {
        $this->typecarburant = $typecarburant;
    }

    /**
     * @return int
     */
    public function getNbcheveaux()
    {
        return $this->nbcheveaux;
    }

    /**
     * @param int $nbcheveaux
     */
    public function setNbcheveaux($nbcheveaux)
    {
        $this->nbcheveaux = $nbcheveaux;
    }

    /**
     * @return \DateTime
     */
    public function getDatemarche()
    {
        return $this->datemarche;
    }

    /**
     * @param \DateTime $datemarche
     */
    public function setDatemarche($datemarche)
    {
        $this->datemarche = $datemarche;
    }

    /**
     * @return int
     */
    public function getNbrPlace()
    {
        return $this->nbrPlace;
    }

    /**
     * @param int $nbrPlace
     */
    public function setNbrPlace($nbrPlace)
    {
        $this->nbrPlace = $nbrPlace;
    }

    /**
     * @return int
     */
    public function getIdUser()
    {
        return $this->idUser;
    }

    /**
     * @param int $idUser
     */
    public function setIdUser($idUser)
    {
        $this->idUser = $idUser;
    }
}

2end

/**
 * Assurance
 *
 * @ORM\Table(name="assurance", indexes={@ORM\Index(name="id_carnet", columns={"id_voiture"})})
 * @ORM\Entity
 */
class Assurance
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id_assurance", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $idAssurance;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="date", type="date", nullable=false)
     */
    private $date;

    /**
     * @var integer
     *
     * @ORM\Column(name="valeur", type="integer", nullable=false)
     */
    private $valeur;

    /**
     * @var string
     *
     * @ORM\Column(name="assurant", type="string", length=255, nullable=false)
     */
    private $assurant;

    /**
     * @var \Voiture
     *
     * @ORM\ManyToOne(targetEntity="Voiture")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_voiture", referencedColumnName="id_voiture")
     * })
     */
    private $idVoiture;

    /**
     * @return int
     */
    public function getIdAssurance()
    {
        return $this->idAssurance;
    }

    /**
     * @param int $idAssurance
     */
    public function setIdAssurance($idAssurance)
    {
        $this->idAssurance = $idAssurance;
    }

    /**
     * @return \DateTime
     */
    public function getDate()
    {
        return $this->date;
    }

    /**
     * @param \DateTime $date
     */
    public function setDate($date)
    {
        $this->date = $date;
    }

    /**
     * @return int
     */
    public function getValeur()
    {
        return $this->valeur;
    }

    /**
     * @param int $valeur
     */
    public function setValeur($valeur)
    {
        $this->valeur = $valeur;
    }

    /**
     * @return string
     */
    public function getAssurant()
    {
        return $this->assurant;
    }

    /**
     * @param string $assurant
     */
    public function setAssurant($assurant)
    {
        $this->assurant = $assurant;
    }

    /**
     * @return \Voiture
     */
    public function getIdVoiture()
    {
        return $this->idVoiture;
    }

    /**
     * @param \Voiture $idVoiture
     */
    public function setIdVoiture($idVoiture)
    {
        $this->idVoiture = $idVoiture;
    }
}

and delete action in controller :

public function deleteVAction($id)
{
  $em = $this->getDoctrine()->getManager();
  $voiture= $em->getRepository('DataBundle:Voiture')->findOneBy(array('idVoiture'=>$id)) ;
  $em->remove($voiture);
  $em->flush();

  return $this->redirectToRoute('User_affiche_voiture') ;
}
Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
  • I'm trying to understand your data model. Does your `Assurance` (Insurance) Entity have many `Voiture`s (Cars)? In other words, an Insurance policy has many cars? In that case, you should have some changes to your ORM mapping. Let us know. Also, you'll need an ArrayCollection to store the Cars. – Alvin Bunk Mar 31 '17 at 03:57
  • You need to explicitely tell the cascade rules. Checkout this post http://stackoverflow.com/questions/16200990/orm-doctrine-manytoone-on-update-cascade-symfony – Amitsouko Mar 31 '17 at 07:29
  • yes but errour show when i shema update cause it's also cascade on my base before i did the mapping – Saif Kouti SaifKouti Mar 31 '17 at 15:35
  • Did you see my comment? – Alvin Bunk Apr 03 '17 at 15:43
  • yes but i need more details it's not clear for me – Saif Kouti SaifKouti Apr 05 '17 at 21:44

0 Answers0