Basic Mapping ============= This chapter explains the basic mapping of objects and properties. Mapping of associations will be covered in the next chapter "Association Mapping". Introduction to Docblock Annotations ------------------------------------ You've probably used docblock annotations in some form already, most likely to provide documentation metadata for a tool like ``PHPDocumentor`` (@author, @link, ...). Docblock annotations are a tool to embed metadata inside the documentation section which can then be processed by some tool. Doctrine generalizes the concept of docblock annotations so that they can be used for any kind of metadata and so that it is easy to define new docblock annotations. In order to allow more involved annotation values and to reduce the chances of clashes with other docblock annotations, the Doctrine 2 docblock annotations feature an alternative syntax that is heavily inspired by the Annotation syntax introduced in Java 5. The implementation of these enhanced docblock annotations is located in the ``Doctrine\Common\Annotations`` namespace and therefore part of the Common package. Doctrine docblock annotations support namespaces and nested annotations among other things. The Doctrine CouchDB ODM defines its own set of docblock annotations for supplying object-relational mapping metadata. **NOTE** If you're not comfortable with the concept of docblock annotations, don't worry, as mentioned earlier Doctrine 2 provides XML and YAML alternatives and you could easily implement your own favourite mechanism for defining metadata. Persistent classes ------------------ In order to mark a class for CouchDB persistence it needs to be designated as an document. This can be done through the ``@Document`` marker annotation. .. code-block:: php getRepository("MyApp\Document\MyPersistentClass"); $john = $repository->findOneBy(array("name" => "John Galt")); Json Names ~~~~~~~~~~ If your fields for some reason have different names in the PHP class and CouchDB document you can use the attribute "jsonName" to specify the name of the key in the json document. Id Mapping ---------- CouchDB documents have a special field "_id" that contains the globally unique identifier of a document in the database. This is always a string, so it suffices to specify only the @Id annotation on the property: .. code-block:: php getRepository("MyApp\Document\MyPersistentClass");