2015-10-03 01:57:40 +08:00
---
layout: docs
title: AttributeCollection
2015-10-04 03:57:50 +08:00
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/attributes/attribute-collection.coffee"
2015-10-03 01:57:40 +08:00
---
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h2 > Summary< / h2 >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< div class = "markdown-from-sourecode" >
< p > < p > Collection attributes provide basic support for one-to-many relationships.
2015-10-02 03:34:16 +08:00
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 >
2015-10-03 01:57:40 +08:00
< / div >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< ul >
< / ul >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h3 > Instance Methods< / h3 >
2015-10-02 03:34:16 +08:00
2015-10-03 01:57:40 +08:00
< h4 id = contains class = "function-name" >
contains(< span class = "args" > < / span > ) < a href = "#contains" class = "link" > < / a >
< / h4 >
2015-10-04 03:57:50 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < / p >
< / div >
2015-10-04 03:57:50 +08:00
2015-10-03 01:57:40 +08:00
< 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 >