Skip to the content
Documentation

Object relations

No ratings yet

Objects can point to other objects. A related object is not a child in the tree: it can be anywhere, and one object can be related to many others. Relations let an article show its author's profile, a product its accessories, and the system know which content still uses an image before it is removed.

Kinds of relations

Kind Made by Name in fetches
Attribute relation An Object relation or Object relations attribute: the editor chooses the related objects in the edit form. The relation belongs to that attribute. attribute
Embed Embedding an object (often an image) in rich text. xml_embed
Link Linking to an object or node from rich text. xml_link
Common relation Added by hand in the edit form's Related content box, without an attribute. common

Relations are stored per version in the table ezcontentobject_link, so each version keeps the relations it had. A relation points to an object, not to one of its nodes.

Reverse relations

Every relation can be read from the other side: "which objects use this image?" The administration shows both directions on the Relations tab of an object. Before content that others point to is removed, moved to the trash or hidden, a confirmation page lists the objects that would lose their target (content.ini [RemoveSettings] ReverseRelationCheck and [HideSettings] ReverseRelationCheck).

In templates

{* the objects chosen in the attribute "related_articles" *}
{foreach $node.data_map.related_articles.content.relation_list as $item}
    {def $related = fetch( 'content', 'object', hash( 'object_id', $item.contentobject_id ) )}
    <a href={$related.main_node.url_alias|ezurl}>{$related.name|wash}</a>
    {undef $related}
{/foreach}

{* every object this one relates to, of all kinds *}
{def $uses = fetch( 'content', 'related_objects', hash( 'object_id', $node.contentobject_id,
                                                        'all_relations', true() ) )}

{* every object that relates to this one: only embeds and attribute relations *}
{def $used_by = fetch( 'content', 'reverse_related_objects',
                       hash( 'object_id', $node.contentobject_id,
                             'all_relations', array( 'xml_embed', 'attribute' ) ) )}

all_relations takes true() for every kind, or a list of the kind names in the table above; attribute_identifier limits the result to one relation attribute.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.