(symfony 1.4.10 & doctrine 1.2)

Hello,

Given the following method, I use a foreach loop in the template to
show students and their group ("Regroupements" here). I would like to
avoid an extra query inside the loop for the group.

EtudiantTable.class.php :
===================
public function getEtudiantsForEnseignement($enseignementId)
{
    $q = $this->createQuery('e')
      ->select('e.nom_naissance, e.nom_usuel, e.prenom, r.id, r.code,
r.type_id, t.id, t.nom')
      ->innerJoin('e.Regroupements r')
      ->innerJoin('r.Type t')
      ->innerJoin('r.EnseignantEnseignementRegroupements eer')
      ->where('eer.enseignement_id=? and e.semestre_id=?',
array($enseignementId, $semestre->getId()))
      ->andWhere('t.code=?', array('groupe'))
      ->orderBy('e.nom_naissance');

    return $q->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
}

With hydration done with  Doctrine_Core::HYDRATE_ARRAY, I can use the
result of this query :

    <?php foreach ($etudiants as $etudiant): ?>
        <?php echo $etudiant['nom_naissance'] ?>
        <?php echo $etudiant['prenom'] ?>
      <?php echo $etudiant['Regroupements'][0]['code'] ?>
    <?php endforeach ?>

But with Doctrine_Core::HYDRATE_RECORD, I write this code, which
generates an extra query for each student :

    <?php foreach ($etudiants as $etudiant): ?>
      <?php echo $etudiant->getNom() ?>
      <?php echo $etudiant->getPrenom() ?>
      <?php echo $etudiant->getGroupe()->getNom() ?>
    <?php endforeach ?>

The code used by these methods are a mix of Doctrines and mine :

Etudiant.class.php :
===============
  public function getGroupe()
  {
    return Doctrine::getTable('Regroupement')->createQuery('r')
      ->select('r.id, r.code')
      ->innerJoin('r.Type t')
      ->innerJoin('r.Etudiants e')
      ->where('e.id=? and t.code=?', array($this->getId(), 'groupe'))
      ->fetchOne();
  }

Regroupement.class.php :
====================
  public function getNom()
  {
    return trim($this->getType()->getNom().' '.$this->getCode());
  }

Would anybody have an idea of how to achieve that with
Doctrine_Core::HYDRATE_RECORD ?

Regards,

Mikael

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to