Faire un SUM avec Doctrine et récupérer la donnée dans indexSuccess.php
Bonjour,
N'ayant trouvé de réponse à ce problème, je me permets de poster.
J'ai un module dans mon frontend "participation" qui liste des personnes participants à un évènement ainsi que le montant de leur participation. J'aimerais créer une colonne "Restant à payer" qui va chercher dans une table "paiement" les paiements associés à la dite participation et faire une soustraction pour savoir le montant restant.
Pour ce faire j'ai donc modifié ma fonction executeIndex :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
public function executeIndex(sfWebRequest $request)
{
/* $this->participations = Doctrine::getTable('Participation')
->createQuery('a')
->execute();*/
$q = Doctrine_Query::create()
->select('p.id, p.idparticipant, p.idevenement, p.montantparticipation, SUM(pa.montant)')
->from('Participation p')
->leftJoin('p.Paiement pa ON p.id = pa.idparticipation')
->groupby('p.id');
$this->participations = $q->execute();
} |
Je récupère ensuite normalement toutes les infos sauf le champ SUM(pa.montant) que je ne sais pas comment appeler.
Code:
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
|
<table>
<thead>
<tr>
<th>Id</th>
<th>Participant</th>
<th>Évenement</th>
<th>Montant participation</th>
<th>Restant à payer</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($participations as $participation): ?>
<tr>
<td><?php echo $participation->getId() ?></td>
<td><?php echo $participation->getParticipant() ?></td>
<td><?php echo $participation->getEvenement() ?></td>
<td><?php echo $participation->getMontantParticipation() ?></td>
<td><?php echo $participation->get????() ?></td>
<td></td>
<td><a href="http://fondacio.aldora.fr/backend.php/paiement/new">Ajouter un paiement</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table> |
Quand je regarde dans les logs la requête SQL s'execute bien et correspont à ce que je souhaite.
Ma question : Ai-je le droit de faire cela, si oui comment puis-je appeler le champ SUM, si non quelle autre solution peut résoudre mon problème ?
Cordialement