Related (to/from)

The majority of relationships you will deal with as a developer are parent/children relationships. However, HiFi allows for a third kind of relationship, simply called a relationship, that does not rely on the site's hierarchical structure (a.k.a. the site tree).

Categories and authors are a good example of this.  Although they are types on par with page and post, they are not children or parents of the content types they are associated with. 

Relationships are directional and they have a name. For example, a post is related to a category and the relationship is named 'category'.  Authors are the same:

{ type: 'post', related: { to:, relation: 'category' } }
{ type: 'category', related: { from:, relation: 'category' } }
{ type: 'gallery', related: { to:, relation: 'author' } }

Notice that each 'related' query requires a 'to' or 'from' parameter. The first query gets posts that are related to a certain category (as indicated by The second retrives any categories related to a specific post. The final query finds all galleries associated with one author.

Note: With parent/children relationships, you can use an id like so:

{ type: 'page', parent: '8234sd875sdf6578'} 

Or a sub query:

{ type: 'post', parent: { type: 'feed', url: '/blog' } }

The sub query is translated to an ID and then used.

This feature isn't currently available for 'related' queries, so you cannot yet do the following:

{ type: 'category', related: { from: { type: 'post', url: '/blog/post-foo'} } }
{ type: 'post', related { to: {type: 'category', url: '/categories/category-name' } } }  

Instead you will have to find the id for the related item and do this in two steps. Here is an example using the HiFi templates.

{% set category as hifi.get({type: 'category', url: '/categories/category-name' })[0] %}
{% set related_posts as hifi.get({type: 'post', related: {to:, relation: 'category'}}) %}