Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update latest changes

  • Loading branch information...
commit 5f7b457ff12333295e4d7914c79aec33779beb52 1 parent b8910c9
Durran Jordan durran authored
Showing with 30 additions and 14 deletions.
  1. +5 −0 en/mongoid/docs/querying.html
  2. +25 −14 en/mongoid/docs/tips.html
5 en/mongoid/docs/querying.html
View
@@ -769,6 +769,11 @@
<div class="CodeRay">
<div class="code"><pre><span class="keyword">class</span> <span class="class">Label</span>&#x000A; include <span class="constant">Mongoid</span>::<span class="constant">Document</span>&#x000A; embeds_many <span class="symbol">:bands</span>&#x000A;<span class="keyword">end</span>&#x000A;&#x000A;<span class="keyword">class</span> <span class="class">Band</span>&#x000A; include <span class="constant">Mongoid</span>::<span class="constant">Document</span>&#x000A; field <span class="symbol">:active</span>, default: <span class="predefined-constant">true</span>&#x000A; embedded_in <span class="symbol">:label</span>&#x000A; default_scoped where(active: <span class="predefined-constant">true</span>)&#x000A;<span class="keyword">end</span>&#x000A;&#x000A;label.bands.push(band)&#x000A;label.bands <span class="comment">#=&gt; [ band ]</span>&#x000A;band.update_attribute(<span class="symbol">:active</span>, <span class="predefined-constant">false</span>)&#x000A;label.bands <span class="comment">#=&gt; [ band ] Must reload.</span>&#x000A;label.reload.bands <span class="comment">#=&gt; []</span>&#x000A;</pre></div>
</div>
+ <p>
+ Note that you should not use default scopes in conjunction with
+ `Mongoid::Paranoia` as the default scope will override the paranoia scope
+ and cause all documents, soft-deleted or not, to be included.
+ </p>
<h3>Class Methods</h3>
<p>
Class methods on models that return criteria objects are also
39 en/mongoid/docs/tips.html
View
@@ -85,11 +85,12 @@
<div class='container'>
<ul class='nav nav-pills'>
<li><a href="#ruby">Ruby 1.9.3</a></li>
- <li><a href="#count_performance">Count Performance</a></li>
- <li><a href="#reorder_embedded">Reordering Embedded Docs</a></li>
+ <li><a href="#count_performance">Counts</a></li>
+ <li><a href="#reorder_embedded">Reordering</a></li>
<li><a href="#gridfs">GridFS</a></li>
- <li><a href="#relational_associations">Relational Associations</a></li>
+ <li><a href="#relational_associations">Relational Data</a></li>
<li><a href="#safe_mode">Safe Mode</a></li>
+ <li><a href="#other_mappers">Other Mappers</a></li>
</ul>
</div>
</div>
@@ -190,18 +191,17 @@
Given this, we did not prioritize any work with GridFS at the front, but
there is a gem in the pipeline for those who can wait a bit to upgrade.
In the meantime you have a few options.
- <li>
- <ul>
- Use the 10gen driver in conjunction with Mongoid 3 and Moped - the
- namespaces will not collide.
- </ul>
- <ul>
- Take advantage of Ara Howard's gist as a starting point to have basic
- GridFS functionality:
- <a href="https://gist.github.com/2407396">GridFS in Mongoid 3</a>
- </ul>
- </li>
</p>
+ <li>
+ <ul>
+ Use the 10gen driver in conjunction with Mongoid 3 and Moped - the
+ namespaces will not collide.
+ </ul>
+ <ul>
+ Take advantage of Ara Howard's <code>mongoid-grid_fs</code> gem:
+ <a href="https://github.com/ahoward/mongoid-grid_fs">mongoid-grid_fs</a>
+ </ul>
+ </li>
</section>
<section id='relational_associations'>
<h2>Relational Associations</h2>
@@ -254,6 +254,17 @@
</ul>
</p>
</section>
+<section id='other_mappers'>
+ <h2>Working With Other Mappers</h2>
+ <p>
+ It's not always the case that you are using MongoDB as your only database, and
+ some apps like to combine databases for different use cases. Below is an example
+ of accessing an Active Record model from Mongoid manually.
+ </p>
+ <div class="CodeRay">
+ <div class="code"><pre><span class="keyword">class</span> <span class="class">Band</span>&#x000A; include <span class="constant">Mongoid</span>::<span class="constant">Document</span>&#x000A;&#x000A; field <span class="symbol">:user_id</span>, type: <span class="constant">Integer</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">user</span>&#x000A; <span class="instance-variable">@user</span> ||= <span class="constant">Band</span>.where(id: user_id).first&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">user=</span>(user)&#x000A; <span class="predefined-constant">self</span>.user_id = user.id&#x000A; <span class="instance-variable">@user</span> = user&#x000A; <span class="keyword">end</span>&#x000A;<span class="keyword">end</span>&#x000A;&#x000A;<span class="keyword">class</span> <span class="class">User</span> &lt; <span class="constant">ActiveRecord</span>::<span class="constant">Base</span>&#x000A;<span class="keyword">end</span></pre></div>
+ </div>
+</section>
</div>
</div>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.