Doctrine 1
  1. Doctrine 1
  2. DC-353

Doctrine_Query can't map a main query colum inside a subquery with join

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0.12, 1.0.14
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None
    • Environment:
      Apache 2.2.13, PHP 5.3, Fedora 11 or Ubuntu 9.04 (and Symfony 1.2.9/1.2.10 with Doctrine 1.0.12/1.0.14)

      Description

      If i have the following schema:

      Medidor:
        tableName: TBLMEDIDOR
        columns:
          CODIGO:
            name: NRCODIGO as codigo
            type: integer(10)
            primary: true
            sequence: SEQMEDCODIGO
          DESCRICAO:
            name: TXDESCRICAO as descricao
            type: string(1000)
            notnull: true
      
      AnaliseMedidor:
        tableName: TBLANALISE_MEDIDOR
        columns:
          CODIGO:
            name: NRCODIGO as codigo
            type: integer(10)
            primary: true
            sequence: SEQANMCODIGO
          DATA:
            name: DTDATA as dataAnalise
            type: date
            notnull: true
          MEDIDOR:
            name: FKMEDCODIGO as medidor_codigo
            type: integer(10)
            notnull: true
          OBSERVACAO:
            name: TXOBSERVACAO as observacao
            type: string(1000)
        relations:
          Medidor: { local: medidor_codigo, foreign: codigo, foreignAlias: Analises }
      

      and execute the following query:

      $query = Doctrine::getTable('Medidor')->createQuery()
          ->innerJoin('m.Analises a')
          ->where('a.dataAnalise = (SELECT MAX(a2.dataAnalise) FROM '
              . 'AnaliseMedidor a2 WHERE a2.medidor_codigo = a.medidor_codigo)');
      

      the "a.medidor_codigo" in the subquery don't get correctly mapped. So Doctrine tells me:

      {sfDoctrineLogger} executeQuery : SELECT t.nr80102codigo AS t__nr80102codigo, t.tx80102descricao AS t__tx80102descricao FROM TBL80102MEDIDOR t INNER JOIN TBL80103ANALISE_MEDIDOR t2 ON t.nr80102codigo = t2.fk80102codigo WHERE t2.dt80103data = (SELECT MAX(t3.dt80103data) AS t3__0 FROM TBL80103ANALISE_MEDIDOR t3 WHERE t3.fk80102codigo = t2.medidor_codigo)
      {Doctrine_Connection_Oracle_Exception} SQLSTATE[HY000]: General error: 904 OCIStmtExecute: ORA-00904: "T2"."MEDIDOR_CODIGO": invalid identifier
       (/root/PDO_OCI-1.0/oci_statement.c:142)
      

      If i put the real name column it runs ok:

      $query = Doctrine::getTable('Medidor')->createQuery()
          ->innerJoin('m.Analises a')
          ->where('a.dataAnalise = (SELECT MAX(a2.dataAnalise) FROM '
              . 'AnaliseMedidor a2 WHERE a2.medidor_codigo = a.FKMEDCODIGO)');
      

      But, this should not be done, right?

      In Doctrine 1.2 it works fine. But in the related versions don't.

        Activity

        Hide
        Arian Maykon de Araújo Diógenes added a comment -

        Haven't added a TestCase because Doctrine 1.0.14 don't have them yet!

        Show
        Arian Maykon de Araújo Diógenes added a comment - Haven't added a TestCase because Doctrine 1.0.14 don't have them yet!

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Arian Maykon de Araújo Diógenes
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: