Data Type: Object

Enables back-door access to associated elements.

Sapwood provides a few means of associating an item with other items, which occurs via the element and elements field types. But in some cases, you want to work in the opposite direction to access associated elements.

Let's look at an example:

Say you have a template called Post and another called Image. And suppose your Post template has a field like so:

"featured_image": {
  "type": "element",
  "templates": ["Image"]

When you access a post, you can get to a post's images. But there isn't a straightforward way to, for instance, get all posts where a particular image is featured. That's where association comes in. You can define a backwards association. On the Image template, that may look like this:

"associations": {
  "posts": {
    "field": "featured_image",
    "template": "Post"