By James


2015-03-19 14:33:36 8 Comments

Let's say I have a team, which has members. I have a content type for team and a content type for individual team members. Let's say there are also other relationships, for instance teams can belong to departments, and there are projects that can be assigned to individuals or teams.

As I understand it there are two ways I can define the relationships between these entities - either Entity references, or using Taxonomy terms. When I should use one type over the other? Is it best to choose just one method, or mix them?

It seems to me that Taxonomy is the most flexible, because it is easy to build trees using taxonomy types, or for instance if within a team I then decided I wanted to build a hierarchy in the team the functionality is already there (just drag the taxonomy terms into the hierarchy) whereas if I've used Entity reference I can't think of a simple way to do that (other than adding taxonomy, which then results in redundancy).

It feels as if there is something I'm not understanding here, but I'm not sure what it is!

Any help would be appreciated.

1 comments

@Zuzuesque 2015-03-19 16:27:44

You are talking about two different concepts here. The first question is related to whenever one wants to organize content into different categories or if one wants to build a relationship between existing content types. The other question is, if, when using a taxonomy, will it be better to use a taxonomy reference field or an entity reference field.


Regarding the first concept

It depends on your use case. Taxonomies are great for building hierarchies, as you mentioned, but ideally, you shouldn’t use taxonomies to contain actual content. The reason for that is easy — while you can add fields to taxonomy terms, all hierarchical levels in a taxonomy use the same fields. Taking your example with members belonging to different teams, this might lead to problems. If you want to store more information about a team or member than just the name, If, for example, you want to store information about a member’s first name, last name, and biography, and add this fields to the taxonomy, they would be available on team terms as well. And if you add a team description field for the teams, those will show up for team members.

Taxonomies are best used when organizing similar items hierarchically. Like tags, for example:

  • vegetable
    • carrot
    • potato
  • fruit
    • apple
    • banana

Entity references are excellent for establishing relationships between content types. Examples include when you have a node type ‘team’ and a node type’ team member,’ each with their own fields. Or a node type ‘song’ which is referencing an ‘album’ which itself references a ‘musician.’ In this regard, entity references are more flexible than taxonomies, as it allows for more complex relationships. When you use views, you can also utilize these relationships. Taking your example, you could create a view of all team members, and using the entity reference for a relationship, and one could display any field on the team content type along with fields from the member node.

Mixing node referenced and taxonomy fields are legit too. In your example with the teams, both team and member could be a node, referencing each other with an entity reference. At the same time, the department could be a taxonomy with all available departments.


Regarding the second concept

When D.O. released D7, it shipped with a taxonomy reference field to use when referencing taxonomies. Since then, we’ve seen the release of the Entity API module and, consequently, the entity reference module, and since terms and taxonomies are entities, one can reference them like any other entity. At this point, the two are working very similarly, and in many cases, it doesn’t matter which one you use. However, there are still some contributed modules providing field formatters and widgets, which only work for one or the other. So, it mostly depends if you need such a formatter if you should use taxonomy reference or entity reference.

As D.O is replacing the taxonomy reference field with the entity reference field in D8, I prefer to go with the entity reference field to link to taxonomies rather than the field supplied by the taxonomy module.

@James 2015-03-19 16:56:33

What a wonderful explanation! Thank you very much! Now I understand!

Related Questions

Sponsored Content

1 Answered Questions

How to display custom fields of taxonomy in field twig

1 Answered Questions

[SOLVED] Entity Query Condition for the referenced entity's type

1 Answered Questions

[SOLVED] How to create an Entity reference with taxonomy term selection?

1 Answered Questions

2 Answered Questions

Pre load entity reference fields into a node

  • 2016-04-10 10:33:52
  • chap
  • 104 View
  • 0 Score
  • 2 Answer
  • Tags:   8 entities

3 Answered Questions

[SOLVED] Hierarchy between terms from different vocabularies in Drupal 7?

  • 2013-12-04 21:50:46
  • user24216
  • 1658 View
  • 7 Score
  • 3 Answer
  • Tags:   taxonomy-terms

1 Answered Questions

Link Taxonomy with Node via Feeds, Entity Reference and Views

2 Answered Questions

[SOLVED] Using CCK or Taxonomy with Custom Fields in Drupal 7

Sponsored Content