2015-10-03 01:57:40 +08:00
---
layout: docs
title: Model
2015-10-04 03:05:22 +08:00
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/models/model.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 > A base class for API objects that provides abstract support for
2015-10-02 03:34:16 +08:00
serialization and deserialization, matching by attributes, and ID-based equality.< / p >
< h2 id = "attributes" > Attributes< / h2 >
2015-10-03 01:57:40 +08:00
< p > < code > id< / code > : < a href = 'attributestring.html' > AttributeString< / a > The resolved canonical ID of the model used in the
2015-10-02 03:34:16 +08:00
database and generally throughout the app. The id property is a custom
getter that resolves to the serverId first, and then the clientId.< / p >
2015-10-03 01:57:40 +08:00
< p > < code > clientId< / code > : < a href = 'attributestring.html' > AttributeString< / a > An ID created at object construction and
2015-10-02 03:34:16 +08:00
persists throughout the lifetime of the object. This is extremely useful
for optimistically creating objects (like drafts and categories) and
having a constant reference to it. In all other cases, use the resolved
< code > id< / code > field.< / p >
2015-10-03 01:57:40 +08:00
< p > < code > serverId< / code > : < a href = 'attributeserverid.html' > AttributeServerId< / a > The server ID of the model. In most cases,
2015-10-02 03:34:16 +08:00
except optimistic creation, this will also be the canonical id of the
object.< / p >
2015-10-03 01:57:40 +08:00
< p > < code > object< / code > : < a href = 'attributestring.html' > AttributeString< / a > The model' s type. This field is used by the JSON
2015-10-02 03:34:16 +08:00
deserializer to create an instance of the correct class when inflating the object.< / p >
2015-10-03 01:57:40 +08:00
< p > < code > accountId< / code > : < a href = 'attributestring.html' > AttributeString< / a > The string Account Id this model belongs to.< / p >
2015-10-02 03:34:16 +08:00
< / 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 >
< h3 > Instance Methods< / h3 >
< h4 id = attributes class = "function-name" >
attributes(< span class = "args" > < / span > ) < a href = "#attributes" class = "link" > < / a >
< / h4 >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < / p >
< / div >
2015-10-04 03:05:22 +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 an < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/array' > Array< / a > of < a href = 'attribute.html' > Attribute< / a > objects defined on the Model' s constructor< / p >
< / td > < / tr >
< / table >
< h4 id = toJSON class = "function-name" >
toJSON(< span class = "args" > < span class = "arg" > [options]< / span > < / span > ) < a href = "#toJSON" class = "link" > < / a >
< / h4 >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < p > Deflates the model to a plain JSON object. Only attributes defined
on the model are included in the JSON.< / p >
< / p >
< / div >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< strong > Parameters< / strong >
< table class = "arguments" >
2015-10-02 03:34:16 +08:00
< tr >
2015-10-03 01:57:40 +08:00
< th > Argument< / th >
< th > Description< / th >
2015-10-02 03:34:16 +08:00
< / tr >
< tr >
2015-10-03 01:57:40 +08:00
< td style = "width:15%;" >
< em > options< / em >
< / td >
< td class = "markdown-from-sourecode" >
< span class = "optional" > Optional< / span >
< p > An < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/object' > Object< / a > with additional options. To skip joined data attributes in the toJSON representation, pass the < code > joined:false< / code > < / p >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< / td >
2015-10-02 03:34:16 +08:00
< / tr >
2015-10-03 01:57:40 +08:00
< / table >
2015-10-04 03:05:22 +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 an < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/object' > Object< / a > with the JSON representation of the model.< / p >
< / td > < / tr >
< / table >
< h4 id = matches class = "function-name" >
matches(< span class = "args" > < span class = "arg" > criteria< / span > < / span > ) < a href = "#matches" class = "link" > < / a >
< / h4 >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< div class = "function-description markdown-from-sourecode" >
< p > < p > Evaluates the model against one or more < a href = 'matcher.html' > Matcher< / a > objects.< / p >
< / p >
< / div >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< strong > Parameters< / strong >
< table class = "arguments" >
2015-10-02 03:34:16 +08:00
< tr >
2015-10-03 01:57:40 +08:00
< th > Argument< / th >
< th > Description< / th >
2015-10-02 03:34:16 +08:00
< / tr >
2015-10-03 01:57:40 +08:00
< tr >
< td style = "width:15%;" >
< em > criteria< / em >
< / td >
< td class = "markdown-from-sourecode" >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< p > An < a href = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/array' > Array< / a > of < a href = 'matcher.html' > Matcher< / a > s to run on the model.< / p >
2015-10-04 03:05:22 +08:00
2015-10-03 01:57:40 +08:00
< / td >
< / tr >
< / table >
2015-10-04 03:05:22 +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 true if the model matches the criteria.< / p >
< / td > < / tr >
< / table >