Doctrine 1
  1. Doctrine 1
  2. DC-417

Unexpected results with equal many-to-many relations

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.6, 1.2.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      PHP 5.2.10-2ubuntu6.3 with Suhosin-Patch 0.9.7 (cli) (built: Nov 26 2009 14:52:57)
      MySQL 5.0.84-0.dotdeb.0
      Doctrine-1.1.6-Sandbox

      Description

      print_r's before refresh represent what i hoped to get and after that what was inserted into db.

      INSERT INTO match_reference (match_id, user_id) VALUES (?, ?)
      Array
      (
          [0] => 2
          [1] => 1
      )
      
      
      UPDATE match_reference SET match_id = ? WHERE user_id = ? AND match_id = ?
      Array
      (
          [0] => 1
          [1] => 1
          [2] => 2
      )
      
      
      INSERT INTO match_reference (match_id, user_id) VALUES (?, ?)
      Array
      (
          [0] => 3
          [1] => 2
      )
      
      
      INSERT INTO match_reference (match_id, user_id) VALUES (?, ?)
      Array
      (
          [0] => 4
          [1] => 2
      )
      Array
      (
          [0] => Array
              (
                  [id] => 2
                  [username] => 2
              )
      
      )
      Array
      (
          [0] => Array
              (
                  [id] => 1
                  [username] => 1
              )
      
          [1] => Array
              (
                  [id] => 3
                  [username] => 3
              )
      
          [2] => Array
              (
                  [id] => 4
                  [username] => 4
              )
      
      )
      Array
      (
      )
      Array
      (
          [0] => Array
              (
                  [id] => 3
                  [username] => 3
              )
      
          [1] => Array
              (
                  [id] => 4
                  [username] => 4
              )
      
      )
      

      schema/schema.yml

      ---
      User:
        columns:
          username: string(255)
        relations:
          Matches:
            class: User
            local: user_id
            foreign: match_id
            refClass: MatchReference
            equal: true
            cascade: [delete]
      
      MatchReference:
        columns:
          user_id:
            type: integer
            primary: true
          match_id:
            type: integer
            primary: true
      

      index.php

      require_once('config.php');
      
      Doctrine::loadModels('models');
      
      Doctrine_Query::create()
          ->delete('User')
          ->execute();
      
      Doctrine_Query::create()
          ->delete('MatchReference')
          ->execute();
      
      $u1 = new User();
      $u1->id = $u1->username = 1;
      $u1->save();
      
      $u2 = new User();
      $u2->id = $u2->username = 2;
      $u2->save();
      
      $u3 = new User();
      $u3->id = $u3->username = 3;
      $u3->save();
      
      $u4 = new User();
      $u4->id = $u4->username = 4;
      $u4->save();
      
      $profiler = new Doctrine_Connection_Profiler();
      Doctrine_Manager::getInstance()->getCurrentConnection()->addListener($profiler);
      
      $user_1 = Doctrine::getTable('User')->find(1);
      
      $matches = Doctrine_Query::create()
          ->from('User')
          ->whereIn('id', array(2))
          ->execute(array(), Doctrine::HYDRATE_ARRAY);
      
      $match = $matches[0];
      
      $user_1->link('Matches', array($match['id']));
      $user_1->save();
      
      $user_2 = Doctrine::getTable('User')->find(2);
      
      $matches = Doctrine_Query::create()
      ->from('User')
      ->whereIn('id', array(3, 4))
      ->execute(array(), Doctrine::HYDRATE_ARRAY);
      
      foreach ($matches as $match) {
          $user_2->link('Matches', array($match['id']));
      }
      
      $user_2->save();
      
      foreach ($profiler as $event) {
          if (in_array($event->getName(), array('execute')) && preg_match('/^(INSERT|UPDATE)/', $event->getQuery())) {
              echo print_r($event->getQuery(), true) . "\n";
              echo print_r($event->getParams(), true) . "\n\n";
          }
      }
      
      print_r($user_1->Matches->toArray());
      print_r($user_2->Matches->toArray());
      
      $user_1->refresh(true);
      $user_2->refresh(true);
      
      print_r($user_1->Matches->toArray());
      print_r($user_2->Matches->toArray());
      
      

        Activity

        Hide
        Ivo Võsa added a comment -

        Just tested it on 1.2.1 with same results.

        Show
        Ivo Võsa added a comment - Just tested it on 1.2.1 with same results.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Ivo Võsa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: