Doctrine 1
  1. Doctrine 1
  2. DC-276

HAVING does not parse column aliases

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0-BETA3
    • Fix Version/s: 1.2.0-RC1
    • Component/s: Query
    • Labels:
      None

      Description

      How to reproduce

      $query->having('<aggregate_alias> <operator> <column_alias>').

      Expected SQL:

       
      ... HAVING <internal_aggregate_alias> <operator> a<N>__<column_name>...
      

      Produced SQL

      ... HAVING <internal_aggregate_alias> <operator> <column_alias> ... /* yes, the same <column_alias> as in ->having() call! */
      

      I've prepared this "real-world example".

      Please fix it someone since I'm forced to invent weird workarounds to emulate this behaviour.

      Thanks in advance.

        Activity

        Hide
        Timo Haberkern added a comment -

        Doesn't work for me in Symfony 1.3.1, Doctrine 1.2.1

        using this DQL:

        Doctrine_Query::create()
        ->select('COUNT(s.status) as cn MIN(s.status) as minstat')
        ->from('LogisticOrder o')
        ->innerJoin('o.Status os')
        ->innerJoin('o.PickingRequests r')
        ->innerJoin('r.Status s')
        ->where('os.status=?', OrderStatusLog::$STATUS_PICKING)
        ->groupBy('r.order_id')
        ->having('minstat=? AND cn=1', array(512))
        ->getSqlQuery();

        I get

        SELECT COUNT(s4.status) AS s4__0 FROM sd_logisticorder s INNER JOIN sd_order_status_log s2 ON s.status_id = s2.id INNER JOIN sd_picking_request s3 ON s.id = s3.order_id INNER JOIN sd_picking_request_status s4 ON s3.id = s4.request_id WHERE (s2.status = ?) GROUP BY s3.order_id HAVING (minstat=? AND cn=1 )

        Show
        Timo Haberkern added a comment - Doesn't work for me in Symfony 1.3.1, Doctrine 1.2.1 using this DQL: Doctrine_Query::create() ->select('COUNT(s.status) as cn MIN(s.status) as minstat') ->from('LogisticOrder o') ->innerJoin('o.Status os') ->innerJoin('o.PickingRequests r') ->innerJoin('r.Status s') ->where('os.status=?', OrderStatusLog::$STATUS_PICKING) ->groupBy('r.order_id') ->having('minstat=? AND cn=1', array(512)) ->getSqlQuery(); I get SELECT COUNT(s4.status) AS s4__0 FROM sd_logisticorder s INNER JOIN sd_order_status_log s2 ON s.status_id = s2.id INNER JOIN sd_picking_request s3 ON s.id = s3.order_id INNER JOIN sd_picking_request_status s4 ON s3.id = s4.request_id WHERE (s2.status = ?) GROUP BY s3.order_id HAVING (minstat=? AND cn=1 )
        Hide
        Timo Haberkern added a comment -

        Just to inform you: The problem is the missing space at the having operators

        Doesn't work:
        ->having('minstat=? AND cn=1', array(512))

        Works:
        ->having('minstat = ? AND cn = 1', array(512))

        Show
        Timo Haberkern added a comment - Just to inform you: The problem is the missing space at the having operators Doesn't work: ->having('minstat=? AND cn=1', array(512)) Works: ->having('minstat = ? AND cn = 1', array(512))

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Andrei Dziahel
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: