title: Understanding Doctrine 2 ORM and how it can and should work with WordPress
body: <p>I would like to integrate Doctrine 2 ORM into WordPress for use in the plugins I'm developing. There is currently a plugin that offers <a href="http://wordpress.org/extend/plugins/doctrine/" rel="nofollow">Doctrine 1.2.3 ORM support in WordPress</a>, but not v2.</p>
  
  <p>The biggest problem I'm having is that I don't understand how Doctrine 2 ORM interacts with my code; specifically, what their <a href="http://www.doctrine-project.org/docs/orm/2.1/en/reference/configuration.html" rel="nofollow">configuration code</a> provides me with and where I should go from here:</p>
  
  <pre><code>// 3.1.1
  require dirname( __FILE__ ) . '/lib/Doctrine/ORM/Tools/Setup.php';
  $lib = dirname( __FILE__ ) . '/lib';
  Doctrine\ORM\Tools\Setup::registerAutoloadDirectory($lib);
  
  // 3.1.2
  use Doctrine\ORM\EntityManager,
      Doctrine\ORM\Configuration;
  
  if($applicationMode == "development") {
      $cache = new \Doctrine\Common\Cache\ArrayCache;
  } else {
      $cache = new \Doctrine\Common\Cache\ApcCache;
  }
  
  $config = new Configuration;
  $config-&gt;setMetadataCacheImpl($cache);
  $driverImpl = $config-&gt;newDefaultAnnotationDriver('/path/to/lib/MyProject/Entities');
  $config-&gt;setMetadataDriverImpl($driverImpl);
  $config-&gt;setQueryCacheImpl($cache);
  $config-&gt;setProxyDir('/path/to/myproject/lib/MyProject/Proxies');
  $config-&gt;setProxyNamespace('MyProject\Proxies');
  
  if ($applicationMode == "development") {
      $config-&gt;setAutoGenerateProxyClasses(true);
  } else {
      $config-&gt;setAutoGenerateProxyClasses(false);
  }
  
  $connectionOptions = array(
      'driver' =&gt; 'pdo_sqlite',
      'path' =&gt; 'database.sqlite'
  );
  
  $em = EntityManager::create($connectionOptions, $config);
  </code></pre>
  
  <p>I had continued reading through sections of the documentation up to section 8 and have some understanding. My questions are:</p>
  
  <ol>
  <li><p>Is this configuration enough to allow me to work with Doctrine 2 ORM in my plugins?</p></li>
  <li><p>Are there any other key steps I'm missing before working with Doctrine 2 ORM? The WordPress plugin seems to automatically generate all of the appropriate classes from the database. I read the documentation a few times, but I feel like I'm missing some big step... or maybe Doctrine 2 ORM is just that much different?</p></li>
  <li><p>Is the EntityManager some global variable that I can use throughout my entities?</p></li>
  <li><p>I assume I have to link everything together, <code>@Entity</code> in a file is not enough for Doctrine to know where the entity is. Is there somewhere in the documentation that defines this?</p></li>
  </ol>
  
  <p>If anyone can provide a quick rundown of how it all works together: configuration, entities, etc. Or provide any clear cut tutorials that may already be out there, I would really appreciate it.</p>