<commit_before>Working with Objects
====================

This chapter explains how to work with the ``DocumentManager`` and the
``UnitOfWork``. The Unit of Work encapsulates the information to be written
to PHPCR when you call ``DocumentManager#flush()``.

A Unit of Work can be manually closed by calling ``DocumentManager#close()``.
Any changes to documents within this UnitOfWork that have not yet been
persisted are lost.

.. note::

    It is very important to understand that only
    ``DocumentManager::flush()`` ever causes write operations against the
    repository to be executed. Any other methods such as
    ``DocumentManager::persist($document)`` or
    ``DocumentManager::remove($document)`` only notify the UnitOfWork to
    perform these operations during flush.

    Not calling ``DocumentManager::flush()`` will lead to all changes
    during that request being lost.

.. tip::

    The ``DocumentManager`` is very similar to the Doctrine ORM EntityManager and
    this chapter is similar to its `corresponding ORM chapter <https://doctrine-orm.readthedocs.org/en/latest/reference/working-with-objects.html>`_.
    This chapter tries to help you by highlighting the places where PHPCR-ODM
    is different from the ORM.


Documents and the Identity Map<commit_msg>update broken link<commit_after>Working with Objects
====================

This chapter explains how to work with the ``DocumentManager`` and the
``UnitOfWork``. The Unit of Work encapsulates the information to be written
to PHPCR when you call ``DocumentManager#flush()``.

A Unit of Work can be manually closed by calling ``DocumentManager#close()``.
Any changes to documents within this UnitOfWork that have not yet been
persisted are lost.

.. note::

    It is very important to understand that only
    ``DocumentManager::flush()`` ever causes write operations against the
    repository to be executed. Any other methods such as
    ``DocumentManager::persist($document)`` or
    ``DocumentManager::remove($document)`` only notify the UnitOfWork to
    perform these operations during flush.

    Not calling ``DocumentManager::flush()`` will lead to all changes
    during that request being lost.

.. tip::

    The ``DocumentManager`` is very similar to the Doctrine ORM EntityManager and
    this chapter is similar to its `corresponding ORM chapter <https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/working-with-objects.html>`_.
    This chapter tries to help you by highlighting the places where PHPCR-ODM
    is different from the ORM.


Documents and the Identity Map
{'fraction_non_alphanumeric': 0.09266409266409266, 'fraction_numerical': 0.0007722007722007722, 'mean_word_length': 4.386694386694387, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7380107', 'n_tokens_mistral': 658, 'n_tokens_neox': 626, 'n_words': 305}