0

I created a custom View, where it shows all of a specific content type. In this content type I have a field that is a user reference called "Assigned to". In this view, I want it exposed so one can search by a username, but this exposed filter only takes in the User ID, but not the user name. What am I missing to make this work?

I added a relationship of User:Assigned_To and that didn't seem to work or I'm not configuring it properly.

enter image description here

1 Answer 1

2

Looks like you're filtering by the actual entity reference field field_assigned, which will naturally just take the user ID because the field itself only knows only about the ID of the referenced entity (specifically, it stores the user ID in the target_id)

In order for you to filter against usernames, you:

  1. Add a filter to the username field.
    • When choosing the field the filter, narrow the category down to User. That way you can find and select the username field.
  2. When configuring the filter, set the relationship to the one that connects your content type to the user via the field_assigned field.
    • This is needed because you can have another entity reference field that also points to User (e.g. something like a "reviewed by"), and Views needs to know which field you meant to use.

Added bonus: Enable SQL debugging in Views settings. That way you can see the resulting SQL query done by Drupal. This will tell you if you're filtering against the right columns or missing some joins.

Your Answer

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

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