Using Relation with Views
The Relation module has integration with Views that allow you to:
- Use existing relations as relationships in views, to join data about other endpoints.
- Use existing relations as relationships in views, to join data about the relation.
- Create lists of relations
Using Views relationships with Relation
For each relation type on your site, Views will provide two kinds of relationships: (entity <-> entity) and (entity <-> relation). The first will join data from the endpoints in the relation – which is usually what you want to do with Views. Using this relationship you will, similarly to how node reference or user reference works, get data about other objects in the relation.
However, you might sometimes want information about the relation itself – such as fields on the relation, or when the relation was created. In these cases you should use the (entity <-> relation) relationship – which will bring you the relation entity rather than the end point entities.
Note:
- Check the "require this relationship" option when configuring relationships to have Views only display relations including the listed object.
- If using a directional relation, you will have the option to select the starting point of the relation as either the source or target – allowing reverse relationships.
- If your relation allows more than one entity type, each possible
(entity <-> entity)and(entity -> relation)combination will show up as a relationship. - When adding two Views relationships of the same type, for example (entity->relation), (relation->entity) then you will get the same entity displayed on both ends of the chain. There is an option to avoid this. Say, node A partcipates in relation 1 then what you get is A-1-A without the unique option.
- As relation itself is an entity, if the relation type allows relating relations then you need to pay special attention to the help text: "from node to relation" means the endpoints of the relation. "The relation table" means the relation metadata. Ie: Node-(the relation table)-Relation endpoint.
View screencast "Relation and Views pt 1"
View screencast "Explanation of the duplicated rows"
Views screencast "More Relation and Views"
(links not available no more, alternatives maybe available here )
Listing relation data in Views
The Relation module exposes the relation data to Views. You can use this either by joining relations into a non-relation view, or create a view with relations as the base data (by selecting the view type relation when creating a new view).
The following handlers provide information about relation entities in Views (explanations only where needed):
- Change date: The time the relation was last changed.
- Create date
- Number of rows: The number of endpoints in the relation.
- Relation type
- Rid: The ID of the relation.
- Uid: The ID of the user creating the relation.
- Vid: The version ID of the relation.
All these handlers are available as both fields, sorting criteria, filters and contextual filters. There is also a number of endpoints handlers available:
- Endpoints (field): The endpoints included in the relation, displayed as links. (Note that this is currently not displaying in Views.)
- endpoints:delta (filter/contextual filter)
- endpoints:entity_id (filter/cotextual filter): The ID of the entity included in a relation.
- endpoints:entity_type (filter/contextual/filter): The type of the entity included in a relation.
- endpoints:r_index (filter/contextual/filter): The row index of the entity included in a relation (starting on 0 for the first end point).
The relationship relation: author is also provided, to join data about the relation author.
Finally, any fields added to relation types are as usual available in Views.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion