Complex References ================== Sometimes you may want to access related documents using custom criteria or from the inverse side of a relationship. You can create an `immutable`_ reference to one or many documents and specify how that reference is to be loaded. The reference is immutable in that it is defined only in the mapping, unlike a typical reference where a `MongoDBRef`_ or identifier (see :ref:`storing_references`) is stored on the document itself. The following options may be used for :ref:`one ` and :ref:`many ` reference mappings: - ``criteria`` - Query criteria to apply to the cursor. - ``repositoryMethod`` - The repository method used to create the cursor. - ``sort`` - Sort criteria for the cursor. - ``skip`` - Skip offset to apply to the cursor. - ``limit`` - Limit to apply to the cursor. Basic Example ------------- In the following example, ``$comments`` will refer to all Comments for the BlogPost and ``$last5Comments`` will refer to only the last five Comments. The ``mappedBy`` field is used to determine which Comment field should be used for querying by the BlogPost's ID. .. code-block:: php createQueryBuilder() ->field('blogPost')->references($blogPost); ->getQuery()->execute(); } } .. _MongoDBRef: http://php.net/manual/en/class.mongodbref.php .. _immutable: http://en.wikipedia.org/wiki/Immutable