J'utilise doctrine pour générer automatiquement mes requêtes et en regardant dans la log, je me rend compte qu' il me génère une requête inutile avant d'exécuter la bonne requêtes.

Mon entité Ticket est lié à un Customer (Many to one) et je souhaite récupéré les tickets liés à un Customer dont je connais l'id. Voici la requête DQL que j'ai créé

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
    $query = $this->getEntityManager()
            ->createQuery('
              SELECT t FROM ExperianFactumailBundle:Ticket t
              WHERE t.customer = ?1')
            ->setParameter(1, $idCustomer);
rien de très sorcier sauf que quand j'exécute ma requête, il effectue 2 requêtes pour récupérer le résultat alors qu'il en suffirait d'une.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
 
SELECT DISTINCT t0_.id AS id0 FROM ticket t0_ WHERE t0_.customer_id = ? LIMIT 10 OFFSET 0
Parameters: ['1']
Time: 0.70 ms
SELECT t0_.id AS id0, t0_.volume AS volume1, t0_.price AS price2, t0_.duration AS duration3, t0_.billing_interval AS billing_interval4, t0_.start_date AS start_date5, t0_.end_date AS end_date6, t0_.disabled AS disabled7, t0_.status AS status8, t0_.routing_type AS routing_type9, t0_.extended AS extended10, t0_.db_id AS db_id11, t0_.customer_id AS customer_id12 FROM ticket t0_ WHERE t0_.customer_id = ? AND t0_.id IN (?, ?, ?)
Parameters: ['1', '1', '3', '4']
Time: 0.80 ms
En fait il se sert de la première requête pour récupérer les id des tickets liés au customer et ensuite il se sert de cette liste d'id pour l'injecter dans uen clause IN.

Je vois pas pourquoi il me convertit ma requête de la sorte alors qu'elle est toute simple.

Je vous mets le code complet de mon entity ca pourra peut être être utile :

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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
 
<?php
 
namespace Experian\FactumailBundle\Entity;
 
use Doctrine\ORM\Mapping as ORM;
 
/**
 * Experian\FactumailBundle\Entity\Ticket
 *
 * @ORM\Table(name="ticket")
 * @ORM\Entity(repositoryClass="Experian\FactumailBundle\Repository\TicketRepository")
 */
class Ticket {
 
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
  private $id;
 
  /**
   * @var  $routingType
   *
   * @ORM\ManyToOne(targetEntity="Experian\FactumailBundle\Entity\Parameter")
   * @ORM\JoinColumns({@ORM\JoinColumn(name="routing_type", referencedColumnName="id")})
   */
  private $routingType;
 
  /**
   * @var string $volume
   *
   * @ORM\Column(name="volume", type="string", length=45, nullable=false)
   */
  private $volume;
 
  /**
   * @var float $price
   *
   * @ORM\Column(name="price", type="float", nullable=true)
   */
  private $price;
 
  /**
   * @var integer $duration
   *
   * @ORM\Column(name="duration", type="integer", nullable=false)
   */
  private $duration;
 
  /**
   * @var integer $billingInterval
   *
   * @ORM\Column(name="billing_interval", type="integer", nullable=true)
   */
  private $billingInterval;
 
  /**
   * @var  $extended
   *
   * @ORM\ManyToOne(targetEntity="Experian\FactumailBundle\Entity\Parameter")
   * @ORM\JoinColumns({@ORM\JoinColumn(name="extended", referencedColumnName="id")})
   */
  private $extended;
 
  /**
   * @var date $startDate
   *
   * @ORM\Column(name="start_date", type="date", nullable=true)
   */
  private $startDate;
 
  /**
   * @var date $endDate
   *
   * @ORM\Column(name="end_date", type="date", nullable=true)
   */
  private $endDate;
 
  /**
   * @var boolean $disabled
   *
   * @ORM\Column(name="disabled", type="boolean", nullable=true)
   */
  private $disabled;
 
  /**
   * @var string $status
   *
   * @ORM\Column(name="status", type="string", length=45, nullable=true)
   */
  private $status;
 
  /**
   * @var Bd
   *
   * @ORM\ManyToOne(targetEntity="Bd")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="db_id", referencedColumnName="id")
   * })
   */
  private $db;
 
  /**
   * @var Customer
   *
   * @ORM\ManyToOne(targetEntity="Customer")
   * @ORM\JoinColumns({
   *   @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
   * })
   */
  private $customer;
 
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId() {
    return $this->id;
  }
 
  /**
   * Set routingType
   *
   * @param integer $routingType
   */
  public function setRoutingType($routingType) {
    $this->routingType = $routingType;
  }
 
  /**
   * Get routingType
   *
   * @return integer 
   */
  public function getRoutingType() {
    return $this->routingType;
  }
 
  /**
   * Set volume
   *
   * @param string $volume
   */
  public function setVolume($volume) {
    $this->volume = $volume;
  }
 
  /**
   * Get volume
   *
   * @return string 
   */
  public function getVolume() {
    return $this->volume;
  }
 
  /**
   * Set price
   *
   * @param float $price
   */
  public function setPrice($price) {
    $this->price = $price;
  }
 
  /**
   * Get price
   *
   * @return float 
   */
  public function getPrice() {
    return $this->price;
  }
 
  /**
   * Set duration
   *
   * @param integer $duration
   */
  public function setDuration($duration) {
    $this->duration = $duration;
  }
 
  /**
   * Get duration
   *
   * @return integer 
   */
  public function getDuration() {
    return $this->duration;
  }
 
  /**
   * Set billingInterval
   *
   * @param integer $billingInterval
   */
  public function setBillingInterval($billingInterval) {
    $this->billingInterval = $billingInterval;
  }
 
  /**
   * Get billingInterval
   *
   * @return integer 
   */
  public function getBillingInterval() {
    return $this->billingInterval;
  }
 
  /**
   * Set extended
   *
   * @param boolean $extended
   */
  public function setExtended($extended) {
    $this->extended = $extended;
  }
 
  /**
   * Get extended
   *
   * @return boolean 
   */
  public function getExtended() {
    return $this->extended;
  }
 
  /**
   * Set startDate
   *
   * @param date $startDate
   */
  public function setStartDate($startDate) {
    $this->startDate = $startDate;
  }
 
  /**
   * Get startDate
   *
   * @return date 
   */
  public function getStartDate() {
    return $this->startDate;
  }
 
  /**
   * Set endDate
   *
   * @param date $endDate
   */
  public function setEndDate($endDate) {
    $this->endDate = $endDate;
  }
 
  /**
   * Get endDate
   *
   * @return date 
   */
  public function getEndDate() {
    return $this->endDate;
  }
 
  /**
   * Set disabled
   *
   * @param boolean $disabled
   */
  public function setDisabled($disabled) {
    $this->disabled = $disabled;
  }
 
  /**
   * Get disabled
   *
   * @return boolean 
   */
  public function getDisabled() {
    return $this->disabled;
  }
 
  /**
   * Set status
   *
   * @param string $status
   */
  public function setStatus($status) {
    $this->status = $status;
  }
 
  /**
   * Get status
   *
   * @return string 
   */
  public function getStatus() {
    return $this->status;
  }
 
  /**
   * Set db
   *
   * @param Experian\FactumailBundle\Entity\Bd $db
   */
  public function setDb(\Experian\FactumailBundle\Entity\Bd $db) {
    $this->db = $db;
  }
 
  /**
   * Get db
   *
   * @return Experian\FactumailBundle\Entity\Bd 
   */
  public function getDb() {
    return $this->db;
  }
 
  /**
   * Set customer
   *
   * @param Experian\FactumailBundle\Entity\Customer $customer
   */
  public function setCustomer(\Experian\FactumailBundle\Entity\Customer $customer) {
    $this->customer = $customer;
  }
 
  /**
   * Get customer
   *
   * @return Experian\FactumailBundle\Entity\Customer 
   */
  public function getCustomer() {
    return $this->customer;
  }
 
  /**
   * Get customer
   *
   * @return Experian\FactumailBundle\Entity\Customer 
   */
  public function getCustomerId() {
    return $this->id;
  }
 
}