Permalink
Browse files

Update for latest 2 fixes

  • Loading branch information...
1 parent 3697c07 commit 0dd66b01e28cff606e1f95a50012ee16d09c2d32 @durran durran committed Jul 7, 2012
Showing with 21 additions and 11 deletions.
  1. +19 −9 en/mongoid/docs/identity_map.html
  2. +2 −2 en/mongoid/docs/tips.html
@@ -77,6 +77,10 @@
<div id='content'>
<div class='container'>
<h1>Identity Map</h1>
+ <p>
+ Mongoid's identity map is an implementation of the
+ <a href="http://martinfowler.com/eaaCatalog/identityMap.html">Identity Map Pattern</a>.
+ </p>
<div class='page-nav'>
<div class='container'>
<ul class='nav nav-pills'>
@@ -101,24 +105,30 @@
<div class="code"><pre><span class="key">identity_map_enabled</span>: <span class="string"><span class="content">true</span></span>&#x000A;</pre></div>
</div>
<p>
+ You can enable the identity map programatically as well.
+ </p>
+ <div class="CodeRay">
+ <div class="code"><pre><span class="constant">Mongoid</span>.identity_map_enabled = <span class="predefined-constant">true</span>&#x000A;</pre></div>
+ </div>
+ <p>
When a document is now loaded from the database, is is automatically
added to the identity map by it's class and id. Subsequent request for
that document by it's id will not hit the database, but rather pull
- the document back from the identity map itself. It's primary function
- in this capacity is to aid in cutting down queries for belongs_to
- relations when iterating over the parents.
+ the document back from the identity map itself.
</p>
<p>
- You can access documents in the map directly via the <tt>get</tt> method.
- It requires the class of the document you want and an id.
+ When performing <code>Model.find</code> queries with the identity map
+ enabled, Mongoid will automatically look for the document in the
+ identity map first and return it if it exists before hitting the database.
</p>
<div class="CodeRay">
- <div class="code"><pre><span class="constant">Mongoid</span>::<span class="constant">IdentityMap</span>.get(<span class="constant">Person</span>, id)&#x000A;</pre></div>
+ <div class="code"><pre><span class="constant">Band</span>.find(id) <span class="comment">#=&gt; Fetch the document from the database.</span>&#x000A;<span class="constant">Band</span>.find(id) <span class="comment">#=&gt; Gets the document from the identity map.</span>&#x000A;&#x000A;<span class="constant">Band</span>.find([ id_one, id_two ]) <span class="comment">#=&gt; Fetch the documents from the database.</span>&#x000A;<span class="constant">Band</span>.find([ id_one, id_two ]) <span class="comment">#=&gt; Gets the documents from the identity map.</span>&#x000A;<span class="constant">Band</span>.find([ id_one, id_three ])&#x000A; <span class="comment">#=&gt; Gets the first document from the identity map, the second from the db.</span>&#x000A;</pre></div>
</div>
<p>
- When performing <code>Model.find</code> queries with the identity map
- enabled, Mongoid will automatically look for the document in the
- identity map first and return it if it exists before hitting the database.
+ Note the identity map does not store <code>nil</code> values if the
+ query to the database did not return any results. So subsequent
+ finds for the same id will hit the database again. This also includes
+ eager loading.
</p>
</section>
<section id='unit_of_work'>
@@ -104,8 +104,8 @@
</p>
<p>
What this means is that prior to 1.9.3, the data received back from big
- endian systems such as SPARC would get incorrect data decoded when receiving
- replys from the database. We have thus made 1.9.3 the minimum requirement
+ endian systems such as SPARC or PPC would get incorrect data decoded when receiving
+ replies from the database. We have thus made 1.9.3 the minimum requirement
to be able to support all architectures.
</p>
<p>

0 comments on commit 0dd66b0

Please sign in to comment.