Bonjour tout le monde,

Je suis entrain de réaliser un blog ou les membres peuvent contacter l'admin(donc moi) par mail...
Et je rencontre deux problème que je vous détaille ci-dessous :

1)
Voici l'entité contactHistorique :
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
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
<?php
 
namespace Lv\BlogBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
 
/**
 * ContactHistorique
 *
 * @ORM\Table(name = "Contact_historique")
 * @ORM\Entity(repositoryClass="Lv\BlogBundle\Entity\ContactHistoriqueRepository")
 */
class ContactHistorique
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
   /**
   * @ORM\ManyToOne(targetEntity="Lv\BlogBundle\Entity\Contact", inversedBy="historique")
   * @ORM\JoinColumn(nullable=false)
   */
    private $contact;
 
    /**
     * @var \DateTime
     * 
     * @ORM\Column(name="date", type="datetime")
     */
    private $date;
 
    /**
	 * @var integer
	 *
	 * @ORM\ManyToOne(targetEntity="Lv\BlogBundle\Entity\ContactEtat", inversedBy="id")
     * @ORM\Column(name="etat_id", type="integer")
    */
    private $etat_id;
 
    /**
     * @var string
     *
     * @ORM\Column(name="commentaire", type="string", length=5000, nullable=true)
     */
    private $commentaire;
 
	public function __construct()
	{
		$this->date = new \Datetime();
	}
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set date
     *
     * @param \DateTime $date
     * @return Contact_historique
     */
    public function setDate($date)
    {
        $this->date = $date;
 
        return $this;
    }
 
    /**
     * Get date
     *
     * @return \DateTime 
     */
    public function getDate()
    {
        return $this->date;
    }
 
    /**
     * Set commentaire
     *
     * @param string $commentaire
     * @return ContactHistorique
     */
    public function setCommentaire($commentaire)
    {
        $this->commentaire = $commentaire;
 
        return $this;
    }
 
    /**
     * Get commentaire
     *
     * @return string 
     */
    public function getCommentaire()
    {
        return $this->commentaire;
    }
 
    /**
     * Set contact
     *
     * @param \Lv\BlogBundle\Entity\Contact $contact
     * @return ContactHistorique
     */
    public function setContact(\Lv\BlogBundle\Entity\Contact $contact)
    {
        $this->contact = $contact;
 
        return $this;
    }
 
    /**
     * Get contact
     *
     * @return \Lv\BlogBundle\Entity\Contact 
     */
    public function getContact()
    {
        return $this->contact;
    }
 
    /**
     * Set etat_id
     *
     * @param integer $etatId
     * @return ContactHistorique
     */
    public function setEtatId($etatId)
    {
        $this->etat_id = $etatId;
 
        return $this;
    }
 
    /**
     * Get etat_id
     *
     * @return integer 
     */
    public function getEtatId()
    {
        return $this->etat_id;
    }
}
Voici l'entité ContactEtat :
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
<?php
 
namespace Lv\BlogBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
 
/**
 * ContactEtat
 *
 * @ORM\Table(name = "Contact_etat")
 * @ORM\Entity(repositoryClass="Lv\BlogBundle\Entity\ContactEtatRepository")
 */
class ContactEtat
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
	 * @ORM\OneToMany(targetEntity="Lv\BlogBundle\Entity\ContactHistorique", mappedBy="etat_id")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
 
    /**
     * @var string
     *
     * @ORM\Column(name="libelle", type="string", length=500)
     */
    private $libelle;
 
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
 
    /**
     * Set libelle
     *
     * @param string $libelle
     * @return ContactEtat
     */
    public function setLibelle($libelle)
    {
        $this->libelle = $libelle;
 
        return $this;
    }
 
    /**
     * Get libelle
     *
     * @return string 
     */
    public function getLibelle()
    {
        return $this->libelle;
    }
}
Voici le début de ma requête :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
$this->createQueryBuilder('ch')
						  ->leftJoin('ch.etat_id', 'ce')
						  ->addSelect('ce')

Voici le message d'erreur que j'obtiens la concernant
:
[Semantical Error] line 0, col 108 near 'ce': Error: Class Lv\BlogBundle\Entity\ContactHistorique has no association named etat_id
500 Internal Server Error - QueryException
1 linked Exception:

QueryException »
Quelqu'un aurait-il une idée pourquoi j'obtiens ce message d'erreur ?!

2) voici la requête SQL que je souhaiterais traduire en doctrine mais étant données que je débute avec doctrine j'ai un peu de mal à voir comment faire, j'espère que quelqu'un pourra m'aider :
Code SQL : 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
SELECT ch.contact_id, 
					ch.date AS date_dernier_etat,
					ce.id AS id_etat,
					ce.libelle AS libelle_etat
				FROM contact_historique AS ch
				INNER JOIN contact_etat ce ON ce.id = ch.etat_id
				INNER JOIN 
				(
					SELECT contact_id, 
						MAX(date) AS max_date
					FROM contact_historique
					GROUP BY contact_id
				) tmp
					ON tmp.contact_id = ch.contact_id
					AND tmp.max_date = ch.date
				ORDER BY ch.contact_id

Merci par avance.