problème relation base de données
Bonjour j'ai encore un problème avec symfony si vous pouviez m'aider, j'ai deux orm emprunt et exemplaire un emprunt contient plusieurs exemplaires
voici l'orm :
exemplaire
Code:
1 2 3 4 5
| manyToOne:
emprunte:
targetEntity: Emprunt
inversedBy: exemplaires
cascade: [ persist ] |
emprunt:
Code:
1 2 3 4 5
| oneToMany:
exemplaires:
targetEntity: Exemplaire
mappedBy: emprunte
orphanRemoval: true |
voici les methodes emprunt.php:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
| <?php
namespace Bib\BiblioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Emprunt
*/
class Emprunt
{
/**
* @var integer
*/
private $id;
/**
* @var \DateTime
*/
private $dateDebut;
/**
* @var \DateTime
*/
private $dateFin;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set dateDebut
*
* @param \DateTime $dateDebut
* @return Emprunt
*/
public function setDateDebut($dateDebut)
{
$this->dateDebut = $dateDebut;
return $this;
}
/**
* Get dateDebut
*
* @return \DateTime
*/
public function getDateDebut()
{
return $this->dateDebut;
}
/**
* Set dateFin
*
* @param \DateTime $dateFin
* @return Emprunt
*/
public function setDateFin($dateFin)
{
$this->dateFin = $dateFin;
return $this;
}
/**
* Get dateFin
*
* @return \DateTime
*/
public function getDateFin()
{
return $this->dateFin;
}
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $exemplaires;
/**
* @var \Bib\BiblioBundle\Entity\Inscrit
*/
private $inscrit;
/**
* Constructor
*/
public function __construct()
{
$this->exemplaires = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add exemplaires
*
* @param \Bib\BiblioBundle\Entity\Exemplaire $exemplaires
* @return Emprunt
*/
public function addExemplaire(\Bib\BiblioBundle\Entity\Exemplaire $exemplaires)
{
$this->exemplaires[] = $exemplaires;
return $this;
}
/**
* Remove exemplaires
*
* @param \Bib\BiblioBundle\Entity\Exemplaire $exemplaires
*/
public function removeExemplaire(\Bib\BiblioBundle\Entity\Exemplaire $exemplaires)
{
$this->exemplaires->removeElement($exemplaires);
}
/**
* Get exemplaires
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getExemplaires()
{
return $this->exemplaires;
}
/**
* Set inscrit
*
* @param \Bib\BiblioBundle\Entity\Inscrit $inscrit
* @return Emprunt
*/
public function setInscrit(\Bib\BiblioBundle\Entity\Inscrit $inscrit = null)
{
$this->inscrit = $inscrit;
return $this;
}
/**
* Get inscrit
*
* @return \Bib\BiblioBundle\Entity\Inscrit
*/
public function getInscrit()
{
return $this->inscrit;
}
public function __toString()
{
return $this->id.'-'.$this->dateDebut.'.'.$this->dateFin;
}
} |
ainsi que exemplaire.php:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| <?php
namespace Bib\BiblioBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Exemplaire
*/
class Exemplaire
{
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $disponibilite;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set disponibilite
*
* @param string $disponibilite
* @return Exemplaire
*/
public function setDisponibilite($disponibilite)
{
$this->disponibilite = $disponibilite;
return $this;
}
/**
* Get disponibilite
*
* @return string
*/
public function getDisponibilite()
{
return $this->disponibilite;
}
/**
* @var \Bib\BiblioBundle\Entity\Livre
*/
private $livre_exemplaire;
/**
* Set livre_exemplaire
*
* @param \Bib\BiblioBundle\Entity\Livre $livreExemplaire
* @return Exemplaire
*/
public function setLivreExemplaire(\Bib\BiblioBundle\Entity\Livre $livreExemplaire = null)
{
$this->livre_exemplaire = $livreExemplaire;
return $this;
}
/**
* Get livre_exemplaire
*
* @return \Bib\BiblioBundle\Entity\Livre
*/
public function getLivreExemplaire()
{
return $this->livre_exemplaire;
}
public function __toString()
{
return $this->disponibilite.'-'.$this->id.'-'.$this->getLivreExemplaire()->getTitre().'-'.$this->getLivreExemplaire()->getNotice();
}
} |
le seul problème est que je veux récupérer la liste des emprunts pour un livre qui possède plusieurs exemplaire, mais dans emprunt je n'ai aucun id qui me rapporte à exemplaire juste à inscrit et dans exemplaire non plus j'ai juste un id qui rapporte à livre comment je peux donc mettre en relation les deux?