Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I'm a Drupal beginner. I'm a bit confused about adding fields to content types.

Case 1: Suppose if I have three content-types Book, Article & White Paper. I created Authors vocabulary which contains list of all Authors.

  1. Now, Should I create "Written by" field (term-reference to Authors) for each content-type or create the field for one content-type and use it in other content types?

  2. What are advantages/disadvantages of either methods?

  3. What happens if I delete a reused-field from one content-type? Does it get deleted in all others?

Case 2: I've follwing content-types: (with specified field requirements)

+--------------+----------------------+
| Content Type | Field Required       |
+--------------+----------------------+
| Book         | Year of publication  |
+--------------+----------------------+
| Presentation | Date of Presentation |
+--------------+----------------------+
| Article      | Date of Publication  |
+--------------+----------------------+
| Event        | Held On              |
+--------------+----------------------+

What should I do? Should I create a single field for one content-type & use it for all other content-types or create field for each content-type?

Help me understand clearly when & how to appropriately re-use existing fields.

share|improve this question

1 Answer 1

up vote 8 down vote accepted

Should I create "Written by" field (term-reference to Authors) for each content-type or create the field for one content-type and use it in other content types?

If you need to collect the same information for different content types, you should use a single field. Your "Written by" field sounds like the perfect case for that. If you had different vocabularies for your authors, say "Book author", "Article author", etc, you'd want (and need) to use separate fields for each.

What are advantages/disadvantages of either methods?

One advantage is that you can query all content types by the one field. So if you find yourself wanting to view all content written by a single author, or even all content written by all authors, it will be easy to create a view to do that. But that's only useful if you need it, obviously. I suppose the main point is that the use case of the field itself will actually dictate the relative advantages/disadvantages of either method.

Also, whenever you create a field, you create two database tables (one for current data, one for revision data). There are, shall we say, "mixed" feelings about whether this method of storage is the best idea from a performance standpoint, and some people prefer to keep the number of tables down. When you attach an existing field to another content type, the same database table is used for all of them, so that box gets ticked. Again though, this only makes sense when your data can be separated.

What happens if I delete a reused-field from one content-type? Does it get deleted in all others?

The field will only be deleted once it has been detached from all content types. Data that belongs to the content type from which you detached the field will be moved into a deleted data table, and purged during cron runs.

On to case 2, and just ask ask yourself this...

Keeping in mind that you can have different labels for each content type's instance of the same field, will that give you enough of a visual (or data-led) cue to let you know the differences between the data?

If so, use a single date field to gain the advantages mentioned above. If not, then it makes more sense to your data design to have separate fields.

It all comes down to what's appropriate for your particular website, but hopefully the above will give you some sort of way forward.

share|improve this answer
    
I didn't understand this: Keeping in mind that you can have different labels for each content type's instance of the same field, will that give you enough of a visual (or data-led) cue to let you know the differences between the data? –  claws Mar 8 at 13:49
4  
I just meant that it's up to you to choose based on what you need to do with your data - taking publication and presentation date as examples, does it matter to you if those are separated out? Do you need to filter content based on that date? Will it give you unwanted results if you use a single field, and get data for all content types when filtering on that field? Those are the sort of questions to ask yourself. It's really a data design issue, Drupal's entity/field system is just the abstraction layer to it. If designing this outside of Drupal, would you put that data in the same table? –  Clive Mar 8 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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