Views are one of the most powerful components of Drupal and a very useful tool for the sitebuilding.
We can create pages, blocks, show lists, filter contents, choose formats, etc. without using any programming, through its user interface.
In this article we are going to talk about one of the options found in the "Advanced" section when we configure a view, which will allow us to create relationships between different entities on our website.
For example, we have a Document content type, with a link to a file, and we want to display the name and surname of the author of the document in a list.
To do this, we must relate the fields "Name" and "Surname" of the user profile with the document node created by the author.
When we create the view of the Document content type, we see that we do not have a user's fields available in the list of available fields.
To have these fields available, we must go into the "Advanced" section and in "Relationships", click on "Add" and select "Content author".
By adding the relationship with the User entity, we will now have all the User fields available, although the view is of the Document content type. When adding fields, we see that the "User" Category is now available.
These User fields will also be available for the others configurations of the view (filters, sort criteria, replacement patterns, etc.). In our case we want to add the fields "Name" and "Surname".
The view would be configured as follows:
And the result would be: