Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing "Undefined index: (fieldname) in Doctrine/ODM/MongoDB/UnitOfWork.php line 736" #433

Closed
vmattila opened this issue Oct 17, 2012 · 2 comments

Comments

@vmattila
Copy link

Hi,

I have recently faced very strange error when trying to update my documents with 1.0.0-beta6 version. The common code for all my trials is as follows:

$dm = $this->get('doctrine_mongodb.odm.default_document_manager');
$session = $dm->getRepository('BrowserSession')->find($this->get('session')->getId());
$session->incrementRequests();

// Continues with one of the code snippets below
  1. If I try to call $dm->persist($session); $dm->flush(); an exception "Undefined index: requests in Doctrine/ODM/MongoDB/UnitOfWork.php line 736" is thrown.

  2. $dm->flush($session); works properly.

  3. $dm->flush(); does not do anything.

I am slightly confused what's going on. Previously, code snippet 1 has worked properly.

The document:

/**
 * @MongoDB\Document()
 * @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT") 
 */
class BrowserSession
{

    // ID and other fields are here

    /**
     * @MongoDB\Increment
     * @var integer
     */
    protected $requests = 0;

    public function incrementRequests() { $this->requests++; }
}
@jmikola
Copy link
Member

jmikola commented Feb 27, 2013

This may be related to #483 (assuming the field name, and not type, is the problem in that issue).

@malarzm
Copy link
Member

malarzm commented Jun 8, 2015

As expected this is working correctly in latest ODM, here's passing test case :)

<?php

namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket;

use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;

class GH433Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
    public function testTest()
    {
        $session = new BrowserSession();
        $this->dm->persist($session);
        $this->dm->flush();
        $this->dm->clear();

        $session = $this->dm->getRepository(get_class($session))->find($session->id);
        $session->incrementRequests();
        $this->dm->persist($session);
        $this->dm->flush();
        $this->dm->clear();

        $session = $this->dm->getRepository(get_class($session))->find($session->id);
        $this->assertEquals(1, $session->requests);
    }
}

/**
 * @MongoDB\Document()
 * @MongoDB\ChangeTrackingPolicy("DEFERRED_EXPLICIT")
 */
class BrowserSession
{
    /** @MongoDB\Id */
    public $id;

    /**
     * @MongoDB\Increment
     * @var integer
     */
    public $requests = 0;

    public function incrementRequests() { $this->requests++; }
}

@malarzm malarzm closed this as completed Jun 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants