1

In a view that displays content of a type that uses an Entity Reference (specifically User reference), I add that relationship but even though multiple users may be/are referenced by the content I only get one of them. Am I missing some sort of configuration?

In the relationship description: "A bridge to the User entity that is referenced via field_users"

EDIT: So after a private discussion with @Anil Sagar it seems that you cannot -using entityreference alone- display multiple results of the referenced entities in one row of the Entity the view displays.

The best you can get is:

Article One
body
image
user1 name
user1 surname

Article One
body
image
user2name
user2surname

(users 1 and 2 are referenced by Article One).

2 Answers 2

0
  • Verify Distinct Checkbox in View Query Settings. You should disable it.
  • Verify number of items to display is more than one.
  • Make sure no filters or contextual filters added that will effect the view results.

I just added a entity reference field to Article Content Type. And then added a relationship to the entity in view using Relationships. It does show multiple values.

I am not sure what other configurations are enabled in your view. See below query generated using views for above scenario.

SELECT node.title AS node_title, node.nid AS nid, users_field_data_field_user.name AS users_field_data_field_user_name, users_field_data_field_user.uid AS users_field_data_field_user_uid, node.created AS node_created, 'node' AS field_data_body_node_entity_type FROM {node} node LEFT JOIN {field_data_field_user} field_data_field_user ON node.nid = field_data_field_user.entity_id AND (field_data_field_user.entity_type = 'node' AND field_data_field_user.deleted = '0') LEFT JOIN {users} users_field_data_field_user ON field_data_field_user.field_user_target_id = users_field_data_field_user.uid WHERE (( (node.status = '1') )) ORDER BY node_created DESC LIMIT 5 OFFSET 0

8
  • "Verify number of items to display is more than one." Where do I find the setting you are refering to?
    – user5005
    Commented Sep 12, 2012 at 12:41
  • @magtak Under Pager settings you can see that...
    – Anil Sagar
    Commented Sep 12, 2012 at 12:42
  • I think you missunderstood the question. I meant that the Entity Reference field has multiple values. Of course I get all the results of the primary content type in my view. What I don't get is all the Entities' fields being referenced by each content.
    – user5005
    Commented Sep 12, 2012 at 12:44
  • Yes, I am talking about Entity Reference field that has multiple values. * I added a user entity reference field. * For node one i selected 4 users * For node two i selected 2 users * I see total 6 results in my view.
    – Anil Sagar
    Commented Sep 12, 2012 at 12:46
  • Is your view fetching Users or Articles?
    – user5005
    Commented Sep 12, 2012 at 12:49
0

Two possible solutions would be either to use views_field_view and have an inner view that fetches all the referenced users by using article nid as a contextual filter,

or, using realname module to display first and last name wherever the username would be shown and remove the reference and add the users as a plain field (but that excludes any other fields that you may wanted to display) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.