[DOCTRINE] relations entre 3 entités

patrice86 Messages postés 1380 Date d'inscription   Statut Membre Dernière intervention   -  
aure2015 Messages postés 93 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

Pour une application sous Symfony 4, j'ai trois entités : Reunion, Client, Commande

Une commande peut être passée en direct par un client (hors d'une réunion) ou bien par un client pendant une réunion (j'ai donc besoin de la relation avec la reunion pour la retrouver)
Il me faut toujours la liaison avec le client surtout lorsque la commande est passée pendant une réunion.

Je ne sais pas comment modéliser cette condition, une table intermédiaire ou bien en jouant sur le nullable ?
Les entités avec un premier test.
Merci


/**
 * @ORM\Entity(repositoryClass="App\Repository\CommandeRepository")
 */
class Commande
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="commandes")
     * @ORM\JoinColumn(nullable=false)
     */
    private $client;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Reunion", inversedBy="commandes")
     */
    private $reunions;



/**
 * @ORM\Entity(repositoryClass="App\Repository\ReunionRepository")
 */
class Reunion
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Client", inversedBy="reunions")
     * @ORM\JoinColumn(nullable=false)
     */
    private $hote;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Client", inversedBy="reunions")
     * @ORM\JoinColumn(nullable=false)
     */
    private $participants;

    <gras>/**
     * @ORM\OneToMany(targetEntity="App\Entity\Commande", mappedBy="reunions")
     */
    private $commandes;</gras>



/**
 * @ORM\Entity(repositoryClass="App\Repository\ClientRepository")
 */
class Client
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Reunion", mappedBy="hote")
     */
    private $reunions;


    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Commande", mappedBy="client")
     */
    private $commandes;
A voir également:
  • [DOCTRINE] relations entre 3 entités
  • Ai suite 3 - Télécharger - Optimisation
  • Picasa 3 - Télécharger - Albums photo
  • Photorecit 3 - Télécharger - Visionnage & Diaporama
  • Imagen 3 - Accueil - Applications & Logiciels
  • Zelda 3 - Accueil - Guide jeu vidéo

1 réponse

aure2015 Messages postés 93 Date d'inscription   Statut Membre Dernière intervention   5
 
Je n'ai jamais utilisé symphony mais pour le mcd, je dirais:

Ta commande est un peu vague car, je ne sais pas trop ce que c'est, si c'est un commande unique:
Client OneToMany Commande
Commande ManyToOne Reunion

Il est possible qu'une commande n'est pas de réunion tout simplement
0