AttributeCollection
Summary
Collection attributes provide basic support for one-to-many relationships. For example, Threads in Mailspring have a collection of Labels or Folders.
When Collection attributes are marked as queryable, the DatabaseStore
automatically creates a join table and maintains it as you create, save,
and delete models. When you call persistModel, entries are added to the
join table associating the ID of the model with the IDs of models in the collection.
Collection attributes have an additional clause builder, contains:
DatabaseStore.findAll(Thread).where([Thread.attributes.categories.contains('inbox')])
This is equivalent to writing the following SQL:
SELECT `Thread`.`data` FROM `Thread`
INNER JOIN `ThreadLabel` AS `M1` ON `M1`.`id` = `Thread`.`id`
WHERE `M1`.`value` = 'inbox'
ORDER BY `Thread`.`last_message_received_timestamp` DESC
The value of this attribute is always an array of other model objects.
Instance Methods
contains()
Returns
| Return Values |
|---|
| Returns a {Matcher} for objects containing the provided value. |