Doctrine 1
  1. Doctrine 1
  2. DC-872

1.2 Documentation on Aggregate Functions Error

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Documentation
    • Labels:
      None

      Description

      In the documentation for using aggregate values with Doctrine Query (link below), there is a code snippet that shows how to access the value of the aggregate field, which does not work.

      The code snippet is:

      //firstsnippet after header
      $q = Doctrine_Query::create()
      ->select('u.id, COUNT(t.id) AS num_threads')
      ->from('User u, u.Threads t')
      ->where('u.id = ?', 1)
      ->groupBy('u.id');

      //second snippet after header
      $users = $q->execute();

      //fourth snippet after header
      echo $users->num_threads . ' threads found';

      The code from the last snippet for accessing the count value, $users->num_threads, doesn't seem to work. What does work for me is:

      //access count value
      echo $users[0]->num_threads

      //My exact code is:
      $query = Doctrine_Query::create()
      ->select('COUNT as batchCount')
      ->from('Batch');
      $result = $query->execute();

      echo $result->batchCount; //10
      echo $result[0]->batchCount; //3 (3 is correct, from direct MySQL command line query)

      It's certainly possible I'm doing something wrong, or that there is a Doctrine_Core attribute I need to set. If there is a Doctrine_Core attribute to set to automatically access aggregate values from the Collection, it would be worth noting at the top of the section.

      Thanks, and thanks for Doctrine (so awesome).

      Link:
      http://www.doctrine-project.org/projects/orm/1.2/docs/manual/dql-doctrine-query-language/hu#select-queries:aggregate-values

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Isaac Foster
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: