I have a Drupal site using paragraphs in which one of the content types, let’s call it a Group
, can contain any number of paragraphs, and each of these paragraphs, let’s call them Members
, contains a reference to a user. I want to get all the uid
s of users which are Members
of a given Group
.
I could accomplish this with a query of the database like
SELECT field_user_target_id FROM paragraph__field_user WHERE entity_id = ( SELECT field_members_target_id FROM node__field_members WHERE entity_id = <GroupID> LIMIT 1 );
for a given GroupID
, but I’m wondering if there’s a way to do this efficiently without directly querying the database. One option would be something like
$group = DrupalnodeEntityNode::load($groupID); $uids = []; foreach ($group->field_members->referencedEntities() as $member) { $uids[] = $member->field_user->target_id; }
but is there a way to do this without having to loop through the Members
?