317 lines
21 KiB
HTML
317 lines
21 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>XML Mapping — Doctrine MongoDB ODM 1.1.5 documentation</title>
|
|
<link rel="stylesheet" href="../_static/bootstrap/css/bootstrap.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/layout.css" type="text/css" />
|
|
<link rel="stylesheet" href="../_static/configurationblock.css" type="text/css" />
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../',
|
|
VERSION: '1.1.5',
|
|
COLLAPSE_MODINDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
|
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../_static/configurationblock.js"></script>
|
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../_static/configurationblock.js"></script>
|
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
<script type="text/javascript" src="../_static/configurationblock.js"></script>
|
|
<script src="../_static/bootstrap/js/bootstrap.min.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
<!--
|
|
$(document).ready(function() {
|
|
$("#versions").change(function() {
|
|
var docsUrl = $(this).val();
|
|
window.location.href = docsUrl;
|
|
});
|
|
});
|
|
-->
|
|
</script>
|
|
<link rel="shortcut icon" href="../_static/doctrine.ico"/>
|
|
<link rel="search" title="Search" href="../search.html" />
|
|
<link rel="top" title="Doctrine MongoDB ODM 1.1.5 documentation" href="../index.html" />
|
|
</head>
|
|
<body>
|
|
<div id="wrapper">
|
|
<div id="header">
|
|
<h1 id="h1title"></h1>
|
|
<div id="logo">
|
|
<a href="http://www.doctrine-project.org/">Doctrine - PHP Database Libraries</a>
|
|
</div>
|
|
</div>
|
|
<div id="nav" class="cls">
|
|
<div class="tl cls">
|
|
<ul>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/">Home</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/about.html">About</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/projects.html">Projects</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/contribute.html">Contribute</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/community.html">Community</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/archive.html">Blog</a></li>
|
|
<li><a target="_top" href="http://www.doctrine-project.org/jira">Development</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div id="content" class="cls">
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li><a href="/">Doctrine Homepage</a> »</li>
|
|
<li><a href="../index.html">Doctrine MongoDB ODM 1.1.5 documentation</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
|
|
<div class="body" >
|
|
|
|
<div class="section" id="xml-mapping">
|
|
<h1>XML Mapping<a class="headerlink" href="#xml-mapping" title="Permalink to this headline">¶</a></h1>
|
|
<p>The XML mapping driver enables you to provide the ODM metadata in
|
|
form of XML documents.</p>
|
|
<p>The XML driver is backed by an XML Schema document that describes
|
|
the structure of a mapping document. The most recent version of the
|
|
XML Schema document is available online at
|
|
<a class="reference external" href="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd</a>.
|
|
The most convenient way to work with XML mapping files is to use an
|
|
IDE/editor that can provide code-completion based on such an XML
|
|
Schema document. The following is an outline of a XML mapping
|
|
document with the proper xmlns/xsi setup for the latest code in
|
|
trunk.</p>
|
|
<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><doctrine-mongo-mapping</span> <span class="na">xmlns=</span><span class="s">"http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"</span>
|
|
<span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
|
<span class="na">xsi:schemaLocation=</span><span class="s">"http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping</span>
|
|
<span class="s"> http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"</span><span class="nt">></span>
|
|
|
|
...
|
|
|
|
<span class="nt"></doctrine-mongo-mapping></span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">If you do not want to use latest XML Schema document please use link like
|
|
<a class="reference external" href="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping-1.0.0-BETA12.xsd">http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping-1.0.0-BETA12.xsd</a>.
|
|
You can change <code class="docutils literal"><span class="pre">1.0.0-BETA12</span></code> part of the URL to
|
|
<a class="reference external" href="https://github.com/doctrine/mongodb-odm/releases">any other ODM version</a>.</p>
|
|
</div>
|
|
<p>The XML mapping document of a class is loaded on-demand the first
|
|
time it is requested and subsequently stored in the metadata cache.
|
|
In order to work, this requires certain conventions:</p>
|
|
<ul class="simple">
|
|
<li>Each document/mapped superclass must get its own dedicated XML
|
|
mapping document.</li>
|
|
<li>The name of the mapping document must consist of the fully
|
|
qualified name of the class, where namespace separators are
|
|
replaced by dots (.).</li>
|
|
<li>All mapping documents should get the extension ".dcm.xml" to
|
|
identify it as a Doctrine mapping file. This is more of a
|
|
convention and you are not forced to do this. You can change the
|
|
file extension easily enough.</li>
|
|
</ul>
|
|
<div class="highlight-php"><div class="highlight"><pre><span class="cp"><?php</span>
|
|
|
|
<span class="nv">$driver</span><span class="o">-></span><span class="na">setFileExtension</span><span class="p">(</span><span class="s1">'.xml'</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>It is recommended to put all XML mapping documents in a single
|
|
folder but you can spread the documents over several folders if you
|
|
want to. In order to tell the XmlDriver where to look for your
|
|
mapping documents, supply an array of paths as the first argument
|
|
of the constructor, like this:</p>
|
|
<div class="highlight-php"><div class="highlight"><pre><span class="cp"><?php</span>
|
|
|
|
<span class="c1">// $config instanceof Doctrine\ODM\MongoDB\Configuration</span>
|
|
<span class="nv">$driver</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">XmlDriver</span><span class="p">(</span><span class="k">array</span><span class="p">(</span><span class="s1">'/path/to/files'</span><span class="p">));</span>
|
|
<span class="nv">$config</span><span class="o">-></span><span class="na">setMetadataDriverImpl</span><span class="p">(</span><span class="nv">$driver</span><span class="p">);</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="section" id="simplified-xml-driver">
|
|
<h2>Simplified XML Driver<a class="headerlink" href="#simplified-xml-driver" title="Permalink to this headline">¶</a></h2>
|
|
<p>The Symfony project sponsored a driver that simplifies usage of the XML Driver.
|
|
The changes between the original driver are:</p>
|
|
<ol class="arabic simple">
|
|
<li>File Extension is .mongodb-odm.xml</li>
|
|
<li>Filenames are shortened, "MyProjectDocumentsUser" will become User.mongodb-odm.xml</li>
|
|
<li>You can add a global file and add multiple documents in this file.</li>
|
|
</ol>
|
|
<p>Configuration of this client works a little bit different:</p>
|
|
<div class="highlight-php"><div class="highlight"><pre><span class="cp"><?php</span>
|
|
<span class="nv">$namespaces</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span>
|
|
<span class="s1">'MyProject\Documents'</span> <span class="o">=></span> <span class="s1">'/path/to/files1'</span><span class="p">,</span>
|
|
<span class="s1">'OtherProject\Documents'</span> <span class="o">=></span> <span class="s1">'/path/to/files2'</span>
|
|
<span class="p">);</span>
|
|
<span class="nv">$driver</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">\Doctrine\ODM\MongoDB\Mapping\Driver\SimplifiedXmlDriver</span><span class="p">(</span><span class="nv">$namespaces</span><span class="p">);</span>
|
|
<span class="nv">$driver</span><span class="o">-></span><span class="na">setGlobalBasename</span><span class="p">(</span><span class="s1">'global'</span><span class="p">);</span> <span class="c1">// global.mongodb-odm.xml</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="section" id="example">
|
|
<h3>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h3>
|
|
<p>As a quick start, here is a small example document that makes use
|
|
of several common elements:</p>
|
|
<div class="highlight-xml"><div class="highlight"><pre>// Documents.User.dcm.xml
|
|
|
|
<span class="cp"><?xml version="1.0" encoding="UTF-8"?></span>
|
|
|
|
<span class="nt"><doctrine-mongo-mapping</span> <span class="na">xmlns=</span><span class="s">"http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"</span>
|
|
<span class="na">xmlns:xsi=</span><span class="s">"http://www.w3.org/2001/XMLSchema-instance"</span>
|
|
<span class="na">xsi:schemaLocation=</span><span class="s">"http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping</span>
|
|
<span class="s"> http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd"</span><span class="nt">></span>
|
|
|
|
<span class="nt"><document</span> <span class="na">name=</span><span class="s">"Documents\User"</span> <span class="na">db=</span><span class="s">"documents"</span> <span class="na">collection=</span><span class="s">"users"</span><span class="nt">></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"id"</span> <span class="na">id=</span><span class="s">"true"</span> <span class="nt">/></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"username"</span> <span class="na">name=</span><span class="s">"login"</span> <span class="na">type=</span><span class="s">"string"</span> <span class="nt">/></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"email"</span> <span class="na">type=</span><span class="s">"string"</span> <span class="na">unique=</span><span class="s">"true"</span> <span class="na">order=</span><span class="s">"desc"</span> <span class="nt">/></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"createdAt"</span> <span class="na">type=</span><span class="s">"date"</span> <span class="nt">/></span>
|
|
<span class="nt"><indexes></span>
|
|
<span class="nt"><index</span> <span class="na">unique=</span><span class="s">"true"</span> <span class="na">dropDups=</span><span class="s">"true"</span><span class="nt">></span>
|
|
<span class="nt"><key</span> <span class="na">name=</span><span class="s">"username"</span> <span class="na">order=</span><span class="s">"desc"</span><span class="nt">></span>
|
|
<span class="nt"><option</span> <span class="na">name=</span><span class="s">"safe"</span> <span class="na">value=</span><span class="s">"true"</span> <span class="nt">/></span>
|
|
<span class="nt"></index></span>
|
|
<span class="nt"></indexes></span>
|
|
<span class="nt"><embed-one</span> <span class="na">target-document=</span><span class="s">"Documents\Address"</span> <span class="na">field=</span><span class="s">"address"</span> <span class="nt">/></span>
|
|
<span class="nt"><reference-one</span> <span class="na">target-document=</span><span class="s">"Documents\Profile"</span> <span class="na">field=</span><span class="s">"profile"</span><span class="nt">></span>
|
|
<span class="nt"><cascade></span>
|
|
<span class="nt"><all</span> <span class="nt">/></span>
|
|
<span class="nt"></cascade></span>
|
|
<span class="nt"></reference-one></span>
|
|
<span class="nt"><embed-many</span> <span class="na">target-document=</span><span class="s">"Documents\Phonenumber"</span> <span class="na">field=</span><span class="s">"phonenumbers"</span> <span class="nt">/></span>
|
|
<span class="nt"><reference-many</span> <span class="na">target-document=</span><span class="s">"Documents\Group"</span> <span class="na">field=</span><span class="s">"groups"</span><span class="nt">></span>
|
|
<span class="nt"><cascade></span>
|
|
<span class="nt"><all</span> <span class="nt">/></span>
|
|
<span class="nt"></cascade></span>
|
|
<span class="nt"></reference-many></span>
|
|
<span class="nt"><reference-one</span> <span class="na">target-document=</span><span class="s">"Documents\Account"</span> <span class="na">field=</span><span class="s">"account"</span><span class="nt">></span>
|
|
<span class="nt"><cascade></span>
|
|
<span class="nt"><all</span> <span class="nt">/></span>
|
|
<span class="nt"></cascade></span>
|
|
<span class="nt"></reference-one></span>
|
|
<span class="nt"></document></span>
|
|
<span class="nt"></doctrine-mongo-mapping></span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Be aware that class-names specified in the XML files should be fully qualified.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last"><code class="docutils literal"><span class="pre">field-name</span></code> is the name of <strong>property in your object</strong> while <code class="docutils literal"><span class="pre">name</span></code> specifies
|
|
name of the field <strong>in the database</strong>. Specifying latter is optional and defaults to
|
|
<code class="docutils literal"><span class="pre">field-name</span></code> if not set explicitly.</p>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="reference">
|
|
<h3>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h3>
|
|
<div class="section" id="lock">
|
|
<span id="xml-reference-lock"></span><h4>Lock<a class="headerlink" href="#lock" title="Permalink to this headline">¶</a></h4>
|
|
<p>The field with the <code class="docutils literal"><span class="pre">lock</span></code> attribute will be used to store lock information for <a class="reference internal" href="transactions-and-concurrency.html#transactions-and-concurrency-pessimistic-locking"><span class="std std-ref">pessimistic locking</span></a>.
|
|
This is only compatible with the <code class="docutils literal"><span class="pre">int</span></code> field type, and cannot be combined with <code class="docutils literal"><span class="pre">id="true"</span></code>.</p>
|
|
<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><doctrine-mongo-mapping></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"lock"</span> <span class="na">lock=</span><span class="s">"true"</span> <span class="na">type=</span><span class="s">"int"</span> <span class="nt">/></span>
|
|
<span class="nt"></doctrine-mongo-mapping></span>
|
|
</pre></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="version">
|
|
<span id="xml-reference-version"></span><h4>Version<a class="headerlink" href="#version" title="Permalink to this headline">¶</a></h4>
|
|
<p>The field with the <code class="docutils literal"><span class="pre">version</span></code> attribute will be used to store version information for <a class="reference internal" href="transactions-and-concurrency.html#transactions-and-concurrency-optimistic-locking"><span class="std std-ref">optimistic locking</span></a>.
|
|
This is only compatible with <code class="docutils literal"><span class="pre">int</span></code> and <code class="docutils literal"><span class="pre">date</span></code> field types, and cannot be combined with <code class="docutils literal"><span class="pre">id="true"</span></code>.</p>
|
|
<div class="highlight-xml"><div class="highlight"><pre><span class="nt"><doctrine-mongo-mapping></span>
|
|
<span class="nt"><field</span> <span class="na">fieldName=</span><span class="s">"version"</span> <span class="na">version=</span><span class="s">"true"</span> <span class="na">type=</span><span class="s">"int"</span> <span class="nt">/></span>
|
|
<span class="nt"></doctrine-mongo-mapping></span>
|
|
</pre></div>
|
|
</div>
|
|
<p>By default, Doctrine ODM updates <a class="reference internal" href="embedded-mapping.html#embed-many"><span class="std std-ref">embed-many</span></a> and
|
|
<a class="reference internal" href="reference-mapping.html#reference-many"><span class="std std-ref">reference-many</span></a> collections in separate write operations,
|
|
which do not bump the document version. Users employing document versioning are
|
|
encouraged to use the <a class="reference internal" href="storage-strategies.html#atomic-set"><span class="std std-ref">atomicSet</span></a> or
|
|
<a class="reference internal" href="storage-strategies.html#atomic-set-array"><span class="std std-ref">atomicSetArray</span></a> strategies for such collections, which
|
|
will ensure that collections are updated in the same write operation as the
|
|
versioned parent document.</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
|
|
<div id="searchbox" style="">
|
|
<h3>Search</h3>
|
|
<form class="search" action="http://readthedocs.org/search/project/" method="get">
|
|
<input type="text" name="q" size="18">
|
|
<input type="submit" value="Go">
|
|
<input type="hidden" name="selected_facets" value="project:">
|
|
</form>
|
|
</div>
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
<ul>
|
|
<li><a class="reference internal" href="#">XML Mapping</a><ul>
|
|
<li><a class="reference internal" href="#simplified-xml-driver">Simplified XML Driver</a><ul>
|
|
<li><a class="reference internal" href="#example">Example</a></li>
|
|
<li><a class="reference internal" href="#reference">Reference</a><ul>
|
|
<li><a class="reference internal" href="#lock">Lock</a></li>
|
|
<li><a class="reference internal" href="#version">Version</a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
<h3>This Page</h3>
|
|
<ul class="this-page-menu">
|
|
<li><a href="../_sources/reference/xml-mapping.rst.txt"
|
|
rel="nofollow">Show Source</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2013, Doctrine Project Team.
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.6.2.
|
|
<br/>
|
|
<a target="_BLANK" href="http://www.servergrove.com"><img src="http://www.doctrine-project.org/_static/servergrove.jpg" /></a> <br/><br/>
|
|
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
|
|
<input type="hidden" name="cmd" value="_s-xclick" />
|
|
<input type="hidden" name="hosted_button_id" value="BAE2E3XANQ77Y" />
|
|
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
|
|
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="bot-rcnr">
|
|
<div class="tl"><!-- corner --></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
|
|
</script>
|
|
<script type="text/javascript">
|
|
_uacct = "UA-288343-7";
|
|
urchinTracker();
|
|
</script>
|
|
<a class="githublink" href="http://github.com/doctrine"><img src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
|
|
</body>
|
|
</html> |