mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
54 lines
2.9 KiB
HTML
54 lines
2.9 KiB
HTML
---
|
|
layout: docs
|
|
title: AttributeCollection
|
|
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/attributes/attribute-collection.coffee"
|
|
---
|
|
|
|
<h2>Summary</h2>
|
|
|
|
<div class="markdown-from-sourecode">
|
|
<p><p>Collection attributes provide basic support for one-to-many relationships.
|
|
For example, Threads in N1 have a collection of Labels or Folders.</p>
|
|
<p>When Collection attributes are marked as <code>queryable</code>, the DatabaseStore
|
|
automatically creates a join table and maintains it as you create, save,
|
|
and delete models. When you call <code>persistModel</code>, entries are added to the
|
|
join table associating the ID of the model with the IDs of models in the collection.</p>
|
|
<p>Collection attributes have an additional clause builder, <code>contains</code>:</p>
|
|
<pre><code class="lang-coffee">DatabaseStore.<span class="hljs-function"><span class="hljs-title">findAll</span><span class="hljs-params">(Thread)</span></span>.<span class="hljs-function"><span class="hljs-title">where</span><span class="hljs-params">([Thread.attributes.labels.contains(<span class="hljs-string">'inbox'</span>)</span></span>])
|
|
</code></pre>
|
|
<p>This is equivalent to writing the following SQL:</p>
|
|
<pre><code class="lang-sql">SELECT <span class="hljs-escape">`T</span>hread<span class="hljs-escape">`.</span><span class="hljs-escape">`d</span>ata<span class="hljs-escape">` </span>FROM <span class="hljs-escape">`T</span>hread<span class="hljs-escape">`
|
|
</span>INNER JOIN <span class="hljs-escape">`T</span>hread-Label<span class="hljs-escape">` </span>AS <span class="hljs-escape">`M</span>1<span class="hljs-escape">` </span>ON <span class="hljs-escape">`M</span>1<span class="hljs-escape">`.</span><span class="hljs-escape">`i</span>d<span class="hljs-escape">` </span>= <span class="hljs-escape">`T</span>hread<span class="hljs-escape">`.</span><span class="hljs-escape">`i</span>d<span class="hljs-escape">`
|
|
</span>WHERE <span class="hljs-escape">`M</span>1<span class="hljs-escape">`.</span><span class="hljs-escape">`v</span>alue<span class="hljs-escape">` </span>= 'inbox'
|
|
ORDER BY <span class="hljs-escape">`T</span>hread<span class="hljs-escape">`.</span><span class="hljs-escape">`l</span>ast_message_received_timestamp<span class="hljs-escape">` </span>DESC
|
|
</code></pre>
|
|
<p>The value of this attribute is always an array of other model objects.</p>
|
|
</p>
|
|
</div>
|
|
|
|
<ul>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Instance Methods</h3>
|
|
|
|
<h4 id=contains class="function-name">
|
|
contains(<span class="args"></span>) <a href="#contains" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns a <a href='matcher.html'>Matcher</a> for objects containing the provided value.</p>
|
|
</td></tr>
|
|
</table>
|