Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem with two Doctrine request
    primarykey
    data
    text
    <p>Hello I have a little problem with requests : In an action executeFiche, I have three requests</p> <pre><code>public function executeFiche(sfWebRequest $request){ // Récupération du logement correspondant à l'ID passé dans l'URL $this-&gt;forward404Unless($this-&gt;logement = Doctrine::getTable('Logement')-&gt;find(array($request-&gt;getParameter('id'))), sprintf('Object logement does not exist (%s).', $request-&gt;getParameter('id'))); // Récupération du (ou des) locataire(s) actuel(s) du logement $locataires = Doctrine::getTable('Logement')-&gt;createQuery('l') -&gt;leftJoin('l.Bail b') -&gt;leftJoin('b.Locataire') -&gt;where('l.id = ?', $request-&gt;getParameter('id')) -&gt;andWhere('(b.datefin &gt;= ?', date('Y-m-d', time())) -&gt;orWhere('b.datefin = 0000-00-00)') -&gt;execute(); // Récupération du (ou des) locataire(s) précédent(s) du logement $locatairesprec = Doctrine::getTable('Logement')-&gt;createQuery('l') -&gt;leftJoin('l.Bail b') -&gt;leftJoin('b.Locataire') -&gt;where('l.id = ?', $request-&gt;getParameter('id')) -&gt;andWhere('b.datefin &lt; ?', date('Y-m-d', time())) -&gt;andWhere('b.datefin != 0000-00-00') -&gt;orderBy('datedeb') -&gt;execute(); $this-&gt;locataires = $locataires; $this-&gt;locatairesprec = $locatairesprec; } </code></pre> <p>The problem is my two requests (the first is alright) hinder themselves and the result returned is wrong.</p> <p><strong>Edit :</strong> SQL request</p> <pre><code> SELECT l.id AS l__id, l.adresse AS l__adresse, l.montee AS l__montee, l.etage AS l__etage, l.numetage AS l__numetage, l.numlogt AS l__numlogt, l.taille AS l__taille, l.surfacehab AS l__surfacehab, l.typelog AS l__typelog, l.intergen AS l__intergen, l.ascenseur AS l__ascenseur, l.ascenseuracc AS l__ascenseuracc, l.accessibl AS l__accessibl, l.adaptable AS l__adaptable, l.adapte AS l__adapte, l.chauffage AS l__chauffage, l.chargeschauf AS l__chargeschauf, l.chargeseauch AS l__chargeseauch, l.chargeseaufr AS l__chargeseaufr, l.reservataire AS l__reservataire, l.loyer AS l__loyer, l.loyercc AS l__loyercc, l.commentaires AS l__commentaires, l.created_at AS l__created_at, l.updated_at AS l__updated_at, b.id AS b__id, b.locataire AS b__locataire, b.logement AS b__logement, b.datedeb AS b__datedeb, b.datefin AS b__datefin, b.colloc AS b__colloc, b.bailglissant AS b__bailglissant, l2.nud AS l2__nud, l2.titre AS l2__titre, l2.nom AS l2__nom, l2.prenom AS l2__prenom, l2.nationalite AS l2__nationalite, l2.datenaissance AS l2__datenaissance, l2.statutmatri AS l2__statutmatri, l2.statutpro AS l2__statutpro, l2.nbenfants AS l2__nbenfants, l2.monoparental AS l2__monoparental, l2.numprec AS l2__numprec, l2.rueprec AS l2__rueprec, l2.quartierprec AS l2__quartierprec, l2.codepostalprec AS l2__codepostalprec, l2.villeprec AS l2__villeprec, l2.statutlogprec AS l2__statutlogprec FROM logement l LEFT JOIN bail b ON l.id = b.logement LEFT JOIN locataire l2 ON b.locataire = l2.nud WHERE (l.id = '1' AND (b.datefin &gt;= '2010-07-01' OR b.datefin = '0000-00-00')) 0.03s, "doctrine" connection # SELECT l.id AS l__id, l.adresse AS l__adresse, l.montee AS l__montee, l.etage AS l__etage, l.numetage AS l__numetage, l.numlogt AS l__numlogt, l.taille AS l__taille, l.surfacehab AS l__surfacehab, l.typelog AS l__typelog, l.intergen AS l__intergen, l.ascenseur AS l__ascenseur, l.ascenseuracc AS l__ascenseuracc, l.accessibl AS l__accessibl, l.adaptable AS l__adaptable, l.adapte AS l__adapte, l.chauffage AS l__chauffage, l.chargeschauf AS l__chargeschauf, l.chargeseauch AS l__chargeseauch, l.chargeseaufr AS l__chargeseaufr, l.reservataire AS l__reservataire, l.loyer AS l__loyer, l.loyercc AS l__loyercc, l.commentaires AS l__commentaires, l.created_at AS l__created_at, l.updated_at AS l__updated_at, b.id AS b__id, b.locataire AS b__locataire, b.logement AS b__logement, b.datedeb AS b__datedeb, b.datefin AS b__datefin, b.colloc AS b__colloc, b.bailglissant AS b__bailglissant, l2.nud AS l2__nud, l2.titre AS l2__titre, l2.nom AS l2__nom, l2.prenom AS l2__prenom, l2.nationalite AS l2__nationalite, l2.datenaissance AS l2__datenaissance, l2.statutmatri AS l2__statutmatri, l2.statutpro AS l2__statutpro, l2.nbenfants AS l2__nbenfants, l2.monoparental AS l2__monoparental, l2.numprec AS l2__numprec, l2.rueprec AS l2__rueprec, l2.quartierprec AS l2__quartierprec, l2.codepostalprec AS l2__codepostalprec, l2.villeprec AS l2__villeprec, l2.statutlogprec AS l2__statutlogprec FROM logement l LEFT JOIN bail b ON l.id = b.logement LEFT JOIN locataire l2 ON b.locataire = l2.nud WHERE (l.id = '1' AND b.datefin &lt; '2010-07-01' AND b.datefin != '0000-00-00') ORDER BY datedeb </code></pre> <p><strong>EDIT</strong></p> <p>Thanks for this answer,</p> <p>But when I want to put the queries in my model, I have others problems : I have an error, with '$request->getParameter('id')'. I exchange it to '$this->getId()' and Doctrine tell me I have an error.</p> <p>For the parenthesis, I close them in the next. I don't know another way to generate SQL with order in the where. It is to have :</p> <pre><code>WHERE l.id = $request-&gt;getParameter('id') AND ( b.datefin &gt;= date('Y-m-d', time()) OR b.datefin = 0000-00-00 ) </code></pre> <p><strong>Edit :</strong> I still have my problem. When the second request have something to return, the first doesn't return all the entries</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload