Framework Symfony

Association plusieurs à plusieurs - Many To Many


a- plusieurs à plusieurs , Bidirectionnel

+cas 1

class Etudiant
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var string
 *
 * @ORM\Column(name="nom", type="string", length=30)
 */
 private $nom;

 /**
 * @var string
 *
 * @ORM\Column(name="prenom", type="string", length=30)
 */
 private $prenom;

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

 /**
 *@ORM\ManyToMany(targetEntity="Matiere", inversedBy="etudiants")
 *@ORM\JoinTable(name="inscription")
 */
 private $matieres;
}


class Matiere
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var string
 *
 * @ORM\Column(name="libelle", type="string", length=30, unique=true)
 */
 private $libelle;

 /**
 *@ORM\ManyToMany(targetEntity="Etudiant", mappedBy="matieres")
 */
 private $etudiants;
}

+cas 2

class Client
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var string
 *
 * @ORM\Column(name="nom", type="string", length=30)
 */
 private $nom;

 /**
 * @var string
 *
 * @ORM\Column(name="tele", type="string", length=13, unique=true)
 */
 private $tele;

 /**
 *@ORM\OneToMany(targetEntity="Commande", mappedBy="client")
 */
 private $commandes;
}
class Produit
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var string
 *
 * @ORM\Column(name="libelle", type="string", length=30)
 */
 private $libelle;

 /**
 * @var float
 *
 * @ORM\Column(name="prix_achat", type="float")
 */
 private $prixAchat;

 /**
 * @var float
 *
 * @ORM\Column(name="prix_vente", type="float")
 */
 private $prixVente;

 /**
 *@ORM\OneToMany(targetEntity="Commande", mappedBy="produit")
 */
 private $commandes;
}
class Commande
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var int
 *
 * @ORM\Column(name="qte", type="integer")
 */
 private $qte;

 /**
 *@ORM\ManyToOne(targetEntity="Client", inversedBy="commandes")
 *@ORM\JoinColumn(name="client_id", referencedColumnName="id")
 */
 private $client;


 /**
 *@ORM\ManyToOne(targetEntity="Produit", inversedBy="commandes")
 *@ORM\JoinColumn(name="produit_id", referencedColumnName="id")
 */
 private $produit;

b- Association ternaire

class Ouvrier
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

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

 /**
 * @var string
 *
 * @ORM\Column(name="grade", type="string", length=30)
 */
 private $grade;

 /**
 *@ORM\OneToMany(targetEntity="Fabrique", mappedBy="ouvriers")
 */
 private $fabriques;
}
class Piece
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var string
 *
 * @ORM\Column(name="libelle", type="string", length=30)
 */
 private $libelle;

 /**
 *@ORM\OneToMany(targetEntity="Fabrique", mappedBy="pieces")
 */
 private $fabriques;
}
class DateFabrication
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

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


 /**
 *@ORM\OneToMany(targetEntity="Fabrique", mappedBy="dates_fabrique")
 */
 private $fabriques;
}
class Fabrique
{
 /**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
 private $id;

 /**
 * @var int
 *
 * @ORM\Column(name="qte", type="integer")
 */
 private $qte;

 /**
 *@ORM\ManyToOne(targetEntity="Client", inversedBy="commandes")
 *@ORM\JoinColumn(name="client_id", referencedColumnName="id")
 */
 private $clients;

 /**
 *@ORM\ManyToOne(targetEntity="Piece", inversedBy="commandes")
 *@ORM\JoinColumn(name="pieces_id", referencedColumnName="id")
 */
 private $pieces;

 /**
 *@ORM\ManyToOne(targetEntity="DateFabrication", inversedBy="commandes")
 *@ORM\JoinColumn(name="date_id", referencedColumnName="id")
 */
 private $dates_fabrique;
}
Partager ce cours avec tes amis :
Rédigé par Mostafa Sedoki
Computer science teacher and the founder of the e-learning platform "developpement-informatique.com", my mission is to provide high-quality courses for free to all computer science students and teachers

Cours Similaires :