Uploaded image for project: 'Doctrine 1'
  1. Doctrine 1
  2. DC-997

Doctrine collections are overwritten when created by inner join queries that agree on the WHERE


    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
    • Environment:
      OS X 10.6.6 with PHP 5.3.3, Windows with PHP 5.3.1


      In brief:
      Doing $result1 = Doctrine_Query::create()>... followed by $result2 = Doctrine_Query::create()>... can lead to a situation where the content of $result1 has become the value in $result2.

      In detail:
      The attached models.yml defines two simple tables with a One-to-Many relationship; we have people and names and each person can have multiple names. The DB can be propagated along the lines of:

      INSERT INTO `tblname` VALUES (1,1,'alpha'),(2,2,'beta'),(3,3,'gamma'),(4,4,'delta'),(5,5,'epsilon'),(6,1,'aleph');
      INSERT INTO `tblperson` VALUES (1),(2),(3),(4),(5);

      Applying the query:

      $results1 = Doctrine_Query::create()
      ->from('Person ppa')
      ->innerJoin('ppa.Name n')
      ->where('ppa.id = ?', 1)
      ->andWhere('n.text = ?', 'alpha')

      and then producing output though

      print 'Results (1): '.count($results1)."\n";
      foreach ($results1 as $result) print $result['text'] . "\n";
      print "\n\n";

      produces the expected:

      Results (1): 1

      Doing a similarly query to a new variable:

      $results2 = Doctrine_Query::create()
      ->from('Person ppa')
      ->innerJoin('ppa.Name n')
      ->where('ppa.id = ?', 1)
      ->andWhere('n.text = ?', 'aleph')

      and printing with

      print 'Results (2): '.count($results2)."\n";
      foreach ($results2 as $result) print $result['text'] . "\n";
      print "\n\n";

      produces the expected:

      Results (2): 1

      but printing out the first result object again at this point gives:

      Results (1): 1

      which is unexpected - "aleph" rather than "alpha".

      If, the second query was altered to

      ->where('ppa.id = ?', 2)
      ->andWhere('n.text = ?', 'beta')

      then all three output results are as expected.

      test.zip contains corresponding test files.

      1. models.yml
        0.5 kB
        Richard Forster


        There are no comments yet on this issue.


          • Assignee:
            guilhermeblanco Guilherme Blanco
            borrible Richard Forster
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: