Search code examples
phpormsymfony1doctrine

Doctrine ORM, two different querys produce the same result set


I'm using Doctrine 1.2 and Symfony 1.4.

In my action, I have two different query that return different result set. Somehow the second query seem to change the result (or the reference?) of the first one and I don't have any clue why..

Here is an example:

  $this->categories = Doctrine_Query::create()
       ->from('Categorie AS c')
       ->innerJoin('c.Activite AS a')
       ->where('a.archive = ?', false)
       ->execute();

  print_r($this->categories->toArray()); // Return $this->categories results, normal behavior.

  $this->evil_query = Doctrine_Query::create()
       ->from('Categorie AS c')
       ->innerJoin('c.Activite AS a')
       ->where('a.archive = ?', true)
       ->execute();

  print_r($this->categories->toArray()); // Should be the same as before, but it return $this->evil_query results instead!

Why Doctrine behave this way ? It's totally driving me crazy. Thanks!

To make it simple it seem like the Query 2 are hijacking the Query 1 result.


Solution

  • In the API docs for the toArray() method in Doctrine_Collection it says:

    Mimics the result of a $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);

    I suspect to answer this question to your satisfaction you're going to have to go through the source code.