Score:1

How do I display field from one content type in another content type

cn flag

I am working with Drupal 9. I found other questions similar, but I do not understand what they are saying to do, and they are 10+ years old so I do not know if they still apply.

Maybe the best way to describe this is how a SQL JOIN might handle it in a query. I created a simple scenario to explain this. In SQL it might be:

SELECT Children.ParentID, Children.ChildID, Children.Name, Parents.Name FROM Parents RIGHT JOIN Children ON Parents.ParentID = Children.ParentID;

This query would return Parents.Name in the query along with the Children fields, which I could then display. A one-to-many relationship.

In a Drupal example, this would be two content types: Parents and Children. They would have a related field: ParentID (in Parents) and ChildrenParentID (in Children). The ParentID in Parents would be unique in that content type.

I want the Children node to display the parents name (Parents.Name) on a view, how do I go about this? I have been looking at Entity Reference but I am not grasping what I need to do to make this work. It seemed like I was linked but it just gave me a field where I could start typing the parent name and it auto-completed from existing content. (I created some test content types to investigate this issue.)

Part of my problem is that I am new to Drupal and I do not understand all the terminology, which makes it hard to do searches for answers or documentation. Any help or links to articles that explain it would be appreciated.

Kevin

leymannx avatar
ne flag
In your content type A's field settings add an entity reference field and configure it to reference content of content type B. In your content type B's display settings create a new view mode "Foobar" and configure it to display only the fields you want to display in content type A. In the content type A's display settings select the view mode the referenced entity will be displayed in ("Foobar"). Create a node of type A and in the reference field select a node of type B. Done.
cn flag
This is frustrating to me. I followed your steps, creating test content types matching your A, B description. If I did it correctly, all I ended up with is a "autocomplete" field that shows the Title field from B. Maybe I missed a step. I do not want an autocomplete field. I want to take a field from content type A and find the (one unique) matching content type B and display a field from B on a view of content type A. Basically a one-to-many relationship where there is one B entity and one or more A entities.
Jaypan avatar
de flag
Autocomplete is the selected (and likely default) form widget. You can go to the _Manage Form_ tab of the entity type, and change the widget for the field.
Jaypan avatar
de flag
Also, Drupal is not a framework that you can just step into and start using. It will only lead to frustrations like you are facing. Buy a book, or pay for some training videos, or read through the developer documentation before actually doing something. You'll want a solid understanding of Drupal terminology before attempting to google solutions or get them here, otherwise the explanations you get will not make a lot of sense. There's a learning curve to Drupal.
cn flag
I did see the alternatives to Autocomplete, but those were not was I was looking for. That helps with input so that you can choose from a list of names instead of a code #. So maybe I posed my question wrong. I was looking for a way to display output in a view for one content type that I can get from a lookup against another content type. The data would already exist as it will be an imported table from an external source. That is what my SQL JOIN example was trying to convey. I will keep reading.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.