Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-29

Persisting changes ordering of elements in embedded collection in some cases

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0ALPHA2
    • Fix Version/s: 1.0.0BETA2
    • Component/s: Persister
    • Labels:
      None

      Description

      After changing ordering of elements in collection, it is persisted incorrectly (with different ordering than expected).

      Here is a test case:

      /** @Document(collection="tests", db="tests") */
      class doc
      {
          /** @Id */
          protected $id;
      
          /** @EmbedMany(targetDocument="emb") */
          protected $collection;
      
          function __construct($c) {$this->set($c);}
      
          function set($c) {$this->collection = $c;}
          function get() {return $this->collection;}
      }
      
      /** @EmbeddedDocument */
      class emb
      {
          /** @String */
          protected $val;
      
          function __construct($val) {$this->val = $val;}
          function get() {return $this->val;}
      }
      
      $collection = new ArrayCollection(array(
          new emb('0'),
          new emb('1'),
          new emb('2')
      ));
      
      // TEST CASE:
      $doc = new doc($collection);
      
      $dm->persist($doc);
      $dm->flush();
      
      // place element '0' after '1'
      $collection = new ArrayCollection(array(
          $collection[1],
          $collection[0],
          $collection[2]
      ));
      
      $doc->set($collection);
      
      $dm->persist($doc);
      $dm->flush();
      
      $dm->refresh($doc);
      
      foreach($doc->get() as $value) {
          echo $value->get() . "\n";
      }
      
      // expecting: 
      // 1
      // 0
      // 2
      
      // getting: 
      // 2
      // 1
      // 0
      

      Is it an issue? Or is it supposed that ordering should be resolved in application code?

        Activity

        Vladimir Razuvaev created issue -
        Jonathan H. Wage made changes -
        Field Original Value New Value
        Fix Version/s 1.0.0BETA1 [ 10080 ]
        Affects Version/s 1.0.0ALPHA2 [ 10065 ]
        Affects Version/s 1.0.0ALPHA1 [ 10064 ]
        Jonathan H. Wage made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Vladimir Razuvaev made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Jonathan H. Wage made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Fix Version/s 1.0.0BETA2 [ 10092 ]
        Fix Version/s 1.0.0BETA1 [ 10080 ]
        Resolution Fixed [ 1 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: