Views - how to pull a 'Node References' associated fields & data whilst it sits in a 'Field Collection'?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
spessex's picture

Hi

If anyone can advise it would be most appreciated as I've been stuck on this for over 48 hours.

I can pull fields and their associated data into a View from two content types using a 'node reference' field type and specifying a 'relationship' within the View but for some reason I cannot appear to do this when the 'node reference field' is contained within a Field Collection. In this instance all it will do is bring back the field titles but without the data.

So to be clear, I have the following:

  • a 'Client Information' content type (ct);
  • a 'Job' ct;
  • the 'Job' ct has a 'Node reference' field (contained within a Field Collection) connecting it to the 'Client Information' ct;
  • I want my View to not only be able to pull the fields and associated data from the 'Job' ct (which I can do) but also the associated fields and data from the 'Client Information' ct;
  • it does work when using a 'relationship' to connect the type in the View if the 'node reference field' is not contained within a Field Collection, but as soon as it goes into a Field Collection it will not pull the data, only the fields.

Any suggestions?

Ste

Comments

For further information and

spessex's picture

For further information and note purposes it appears the main difference in 'adding a relationship' in a view with those 'node reference' fields 'not contained' within a 'Field Collection' and those 'contained' within a Field Collection is that;

1 - when the 'node reference' 'is not contained' within a FC there is an option to select 'Content: Name Of Field (field_name_of_field), Appears in: node:name_of_content_type - and this works and pulls in all the desired information (field titles and associated data).

whereas

2 - when the 'node reference' 'is contained' within a FC there is an option to select 'Content: Name Of Field (field_name_of_field)-reverse, Relate each Field collection item referencing the node through Name Of Field - this does not work and only pulls the field titles.

Thanks to Johan Falk from

spessex's picture

Thanks to Johan Falk from NodeOne who guided me toward using entity reference instead of node reference to get to the same solution. This works with Field Collection and Views Relationships.

As a side note I also noticed whilst working on this that Hierarchical Select does not appear to work with entity reference when pulling it into a view and instead standard select or autocomplete fields should be used instead.

Thanks!

jnorell's picture

Thank you, spessex (and Johan), this really had me stumped. Entity References worked quite well.

Same Problem

ABaier's picture

Hello spessex,

could you please explain it more detailled how you solved the problem
with entity reference, field collection and views?

I have the following two content-types:

  1. THEATER-PLAY:
    Includes the field collection with a "role-name" (text-field) and an entity reference to an actors content-type
  2. ACTOR:
    Includes some necessary fields

In my view I want to filter the plays the actor took part in, showing the "role-name" and the title of the
"THEATER-PLAY" in which the actors-page was referenced. Unfortunately the title shows only the name of the
actor itself, not the one of the play, while the role-name was pulled correctly.

I set up a reverse relationship to "Entity Reference: Referencing entity" of the field collection entity reference field
as usual and set it required. But now I can`t figure out how to get the node-title of the "THEATER-PLAY" content-
type instead of the actors-name.

Referencing entities outside of the field collection works as expected.

I would really appreciate your help.

Thanks in advance,

Anton

Hi Anton It's been a while

spessex's picture

Hi Anton

It's been a while now so I'm doing this from memory.

If I remember correctly you do not need to setup a reverse relationship. I did it this way to start with but ended up using a standard entity ref: referencing entity link in the end. From there I'm sure it then brings in other options for you to reach, something like a 'Bridge to Field Collection Referencing .... [your content name]'.

Also depending on your setup, some relationships sometimes also then have to have an additional relationship referencing one of the existing relationships if that makes sense.

Once you have these setup they will then appear in your field section.

Unfortunately I had to use a lot of trial and error with adding relationships, linking to other relationships and then seeing if the fields became available and then testing the various relationship links with the fields until finally some data was pulled through. Not a great method I know but I'm still very much a newbie.

If you're still struggling and it's accessible across the internet (www.getpantheon.com is good for staging test sites and it's also free for this type of usage) I can always try and have a look for you when I get 5 mins.

Ste

Field Collection is of type "text"

emb03's picture

Can I create this bridge using a text field (not an entity reference field)? My field collection is text because the editor supplies the name of the donor. I would like to use a bridge to list by donor name (once) and then list all the nodes associated with that donor.