mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
33 lines
1.7 KiB
HTML
33 lines
1.7 KiB
HTML
---
|
|
layout: docs
|
|
title: AttributeJoinedData
|
|
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/attributes/attribute-joined-data.coffee"
|
|
---
|
|
|
|
<h2>Summary</h2>
|
|
|
|
<div class="markdown-from-sourecode">
|
|
<p><p>Joined Data attributes allow you to store certain attributes of an
|
|
object in a separate table in the database. We use this attribute
|
|
type for Message bodies. Storing message bodies, which can be very
|
|
large, in a separate table allows us to make queries on message
|
|
metadata extremely fast, and inflate Message objects without their
|
|
bodies to build the thread list.</p>
|
|
<p>When building a query on a model with a JoinedData attribute, you need
|
|
to call <code>include</code> to explicitly load the joined data attribute.
|
|
The query builder will automatically perform a <code>LEFT OUTER JOIN</code> with
|
|
the secondary table to retrieve the attribute:</p>
|
|
<pre><code class="lang-coffee">DatabaseStore.find<span class="hljs-function"><span class="hljs-params">(Message, <span class="hljs-string">'123'</span>)</span>.<span class="hljs-title">then</span> <span class="hljs-params">(message)</span> -></span>
|
|
<span class="hljs-comment"># message.body is undefined</span>
|
|
|
|
DatabaseStore.find<span class="hljs-function"><span class="hljs-params">(Message, <span class="hljs-string">'123'</span>)</span>.<span class="hljs-title">include</span><span class="hljs-params">(Message.attributes.body)</span>.<span class="hljs-title">then</span> <span class="hljs-params">(message)</span> -></span>
|
|
<span class="hljs-comment"># message.body is defined</span>
|
|
</code></pre>
|
|
<p>When you call <code>persistModel</code>, JoinedData attributes are automatically
|
|
written to the secondary table.</p>
|
|
<p>JoinedData attributes cannot be <code>queryable</code>.</p>
|
|
</p>
|
|
</div>
|
|
|
|
<ul>
|
|
</ul>
|