L'idée est de créé une bibliothèque de livre un livre peux avoir plusieurs langues et plusieurs auteurs, donc j'ai créer trois entity et deux relations.
J'ai un entity Livre qui possède deux relations ManyToMany
Code : Tout sélectionner
**
* Livre
* @ORM\Table()
* @ORM\Entity(repositoryClass="LivreBundle\Entity\LivreRepository")
*/
class Livre
{
/**
* @ORM\ManyToMany(targetEntity="LivreBundle\Entity\Langue")
*
*/
private $langue;
/**
* @ORM\ManyToMany(targetEntity="Gilnet\LivreBundle\Entity\Auteur", cascade={"persist"})
*/
private $auteur;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
* @ORM\Column(name="titre", type="string", length=150)
*/
private $titre;
/**
* @var string
* @ORM\Column(name="description", type="text")
*/
private $description;
/**
* Livre constructor.
*/
public function __construct()
{
//$this->date = new \Datetime();
$this->auteur = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set titre
*
* @param string $titre
* @return Livre
*/
public function setTitre($titre)
{
$this->titre = $titre;
return $this;
}
/**
* Get titre
*
* @return string
*/
public function getTitre()
{
return $this->titre;
}
/**
* Set langue
*
* @param string $langue
* @return Livre
*/
public function setLangue($langue)
{
$this->langue = $langue;
return $this;
}
/**
* Get langue
*
* @return string
*/
public function getLangue()
{
return $this->langue;
}
/**
* Set auteur
*
* @param string $auteur
* @return Livre
*/
public function setAuteur(Auteur $auteur)
{
$this->auteur = $auteur;
return $this;
}
/**
* Get auteur
*
* @return string
*/
public function getAuteur()
{
return $this->auteur;
}
/**
* @param Auteur $auteur
* @return $this
*/
public function addCategory(Auteur $auteur)
{
$this->auteur[] = $auteur;
return $this;
}
/**
* @param Auteur $auteur
*/
public function removeAuteur(Auteur $auteur)
{
$this->auteur->removeElement($auteur);
}
/**
* Set description
*
* @param string $description
* @return Livre
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}
/**
* Get description
*
* @return string
*/
public function getDescription()
{
return $this->description;
}
}Une piste peut-être ?
d'avance merci