J'aimerais afficher les résultats de deux tables reliés entre elles par une jointure Many to Many.
Voici ma première table:
Et la deuxieme:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php namespace Essai\ManyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Essai\ManyBundle\Entity\Proprietaire * * @ORM\Table() * @ORM\Entity(repositoryClass="Essai\ManyBundle\Entity\ProprietaireRepository") */ class Proprietaire { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nom * * @ORM\Column(name="nom", type="string", length=255) */ private $nom; /** * @var string $prenom * * @ORM\Column(name="prenom", type="string", length=255) */ private $prenom; /** * @ORM\ManyToMany(targetEntity="Autre",inversedBy="proprietaires") * @ORM\JoinTable(name="proprietaire_autres") * @ORM\JoinColumn(name="autres_id", referencedColumnName="id") */ private $autres; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set nom * * @param string $nom */ public function setNom($nom) { $this->nom = $nom; } /** * Get nom * * @return string */ public function getNom() { return $this->nom; } /** * Set prenom * * @param string $prenom */ public function setPrenom($prenom) { $this->prenom = $prenom; } /** * Get prenom * * @return string */ public function getPrenom() { return $this->prenom; } public function __construct() { $this->autres = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add autres * * @param Essai\ManyBundle\Entity\Autre $autres */ public function addAutre(\Essai\ManyBundle\Entity\Autre $autres) { $this->autres[] = $autres; } /** * Get autres * * @return Doctrine\Common\Collections\Collection */ public function getAutres() { return $this->autres; } }
Dans MySql les tables crées sont
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php namespace Essai\ManyBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Essai\ManyBundle\Entity\Autre * * @ORM\Table() * @ORM\Entity(repositoryClass="Essai\ManyBundle\Entity\AutreRepository") */ class Autre { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $adresse * * @ORM\Column(name="adresse", type="string", length=255) */ private $adresse; /** * @ORM\ManyToMany(targetEntity="Proprietaire", mappedBy="autres") */ private $proprietaires; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set adresse * * @param string $adresse */ public function setAdresse($adresse) { $this->adresse = $adresse; } /** * Get adresse * * @return string */ public function getAdresse() { return $this->adresse; } public function __construct() { $this->proprietaires = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add proprietaires * * @param Essai\ManyBundle\Entity\Propietaire $proprietaires */ public function addPropietaire(\Essai\ManyBundle\Entity\Propietaire $proprietaires) { $this->proprietaires[] = $proprietaires; } /** * Get proprietaires * * @return Doctrine\Common\Collections\Collection */ public function getProprietaires() { return $this->proprietaires; } /** * Add proprietaires * * @param Essai\ManyBundle\Entity\Proprietaire $proprietaires */ public function addProprietaire(\Essai\ManyBundle\Entity\Proprietaire $proprietaires) { $this->proprietaires[] = $proprietaires; } }
-autre
-proprietaire
proprietaire_autres
Donc je repète ma question.
Comment faire pour afficher les résultats dans une page. EX:
nom prenom adresse
Merci beaucoup
Partager