11

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.

  • Ok, I've made some progress in understanding - an Entity reference can actually be to a Taxonomy term! so "Team B" could actually be both a Content Type (containing the description) and an Entity reference link to a Taxonomy term (of the same name). Then a user could be linked to the Taxonomy term, rather than the content type... – James Mar 19 '15 at 14:51
  • I guess one thing I still haven't worked out is - what is the difference between having a field in a content type that is a taxonomy term, and an entity reference that links to a taxonomy term - the latter just seems like an additional level of complication. – James Mar 19 '15 at 14:58
  • They are pretty comparable. Out of consistency, I like to use Entity Reference. – alex laughnan Mar 19 '15 at 15:15
  • But if you use Entity reference there are still instances when it is still better to use taxonomy aren't there? So for instance if we have an organisation hierarchy, it would seem to me that taxonomy is a better way to do that. – James Mar 19 '15 at 15:19
20

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

On the first point:

It absolutely depends on your use case. Taxonomies as great for building hierachies as you mentioned, but ideally they shouldn't be used to contain actual content. The reason for that is easy - while you can add fields to taxonomy terms, all hierachy 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 members firstname, lastname 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 whould show up for team members.

Taxonomies are best used when organizing similar items in a hierachical fasion. Like tags for example:

- vegetable
    - carrot
    - potatoe
- fruit
    - apple
    - banana

Entity references are great for establishing relationships between content types. Like 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 actually 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 could display any field on the team content type along with fields from the member node.

Mixing node referenced and taxonomy fields is absolutely legit too. In your example with the teams, both team and member could be a node, referencing each other with entity reference, while department could be a taxonomy with all available departments.

On the second point

When D7 was released it shipped with a taxonomy reference field to use when referencing taxonomies. Since the release the Entity API module and consequently the entity reference module where created (and since terms and taxonomies are entites they can be referenced 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 contrib modules providing field formatters/widgets which only work for one or the others. So it mostly depends if you need such a formatter if you should use taxonomy reference or entity reference.

As the taxonomy reference field will be replaced by the entity reference field in D8 I personally prefer to go with the entity reference field to link to taxonomies rather than the field supplied by the taxonomy module.

  • 2
    What a wonderful explanation! Thank you very much! Now I understand! – James Mar 19 '15 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.