Advertising sustains the DA. Ads are hidden for members. Join today

Contributed modules documentation

Relation

Conceptual image of relations

The Relation module provides an API and basic user interface for creating and managing relations between entities on your Drupal site.

The Relation module is similar to modules like Entity Reference and References (node reference and user reference), but has some important differences:

  • Relations are their own entities, existing strictly outside both entities they relate to (where references are attached to the source entity).
  • Being separate entities, relations are also fieldable (where references are not).
  • Relations can include multiple endpoints (where references only have two).
  • Relations can be directional or symmetrical (where references always have an explicit starting point – thereby being directional).

These properties allow more complex information structure on your site, but also make relations more complex to set up compared to references. It should be noted that while the Relation module has a UI for managing relations, it is to a large extent an API module for other modules to implement.

Relation has good integration with the Feeds, Migrate, Views and Rules modules – see separate sections for details on how to utilize this.

Some use cases

  • Relations can relate more than two entities:
    areSiblings -> (john, jen, jack, jess)
  • Relations with two endpoints, 2-ary or binary relations, can be directional:
    bruno -> isChildOf -> boglarka
  • Directional relations automatically provides a reverse relation:
    boglarka -> isParentOf -> bruno
  • 1:n directional relations are also possible:
    john -> playlist -> (Song A, Song B, Song C)
  • Relations are fieldable: on the relation
    CompanyA -> donation[123] -> PartyB,
    donation[123] may have fields for amount, date, message, etc.
  • Being entities, relations can relate to other relations:
    CompanyA -> donation[123] -> PartyB and
    donations[123] -> transaction[456] -> BankC
    (that is, "Company A made a donation to Political Party B, via Bank C"). See the RDF spec for n-ary relations for more information about relation descriptions. [Note: this isn't a standard, and may never be]).

View a screencast introducing the Relation module

Creating and managing relations

Creating new relations

Creating relation types

Your site may have many different types of relations, containing different information and being used for different purposes. This is

Installing and uninstalling the Relation module

Relation is installed using the standard Drupal procedure – see Installing contributed modules (Drupal 7) for details.

Related modules

Related modules

Using Relation with Rules

The Relation module has integration with Rules, primarily to allow creating new relations. It is also possible, but slightly awkward, to

Using Relation with Views

The Relation module has integration with Views that allow you to:

Using the Relation Entity Collector block

The Relation Entity Collector block module provides your site with a simple user interface for creating relations manually. To use it, you

Viewing relations with Relation Dummy Field

The Relation Dummy Field module provides a pseudo-field that can be added like other fields on your site.

Guide maintainers

naught101's picture