If I have two content types with a relationship between them in Drupal 8, in order to represent the relationship, I can put a reference field to the other content type in one of these two content types.
But in this video tutorial, it shows an example where both content types contains a reference field to each other.
In what situations would I want to put a reference field in both content types?
1 Answers
Answers 1
If you are user of the example website in the video, I can think of these two use cases:
I am viewing the Event Detail Page, then I want to know who is sponsoring the event.
I am viewing the User Group Detail Page, then I want to know what events the group is sponsoring.
Then you would have to discuss the implementation.
In the video, they go for two reference fields, I see it as a shortcut so that you have your Event Detail Page and User Group Detail Page ready. But then you have a new problem, you will have to keep both fields in sync. Having this type of redundancy wouldn't be considered a good practice in database design.
Alternatively, if you don't want to deal with field synchronization, you only need a reference field. Let's say the Event will have the reference field, now we would have to come up with a way to query the events of a group for the User Group Detail Page. A Drupal View would be the most common way to do this.
I think the instructor in the video doesn't want to introduce views at this point of the training, because it is a broad topic, then probably he will go back and revisit the implementation later in the course.
0 comments:
Post a Comment