Score:1

Paragraph Entity Query returns too many results

cn flag

I'm trying to find a paragraph that have a certain taxonomy term value and on a matching parent node. I tried the code below, but it always returns over 30 values, when really only one paragraph entity is possible. Not sure what I'm missing.

$query = \Drupal::entityQuery('paragraph')
    ->condition('status', 1)
    ->condition('type', 'player_assignment')
    ->condition('field_year_season', $term_id)
    ->condition('parent_id', $node_id);

$results = $query->execute();
Kevin avatar
in flag
Have you looked with a database client to see what records are returned? I am going to wager a guess they are all 'status 1'.
Score:1
cn flag

If this returns 30 paragraphs then all of them were at some point stored in the parent node, but not necessarily in the current revision. It might be easier to load the node and then check the paragraph field content of the current revision or, in case you don't know the node ID, start your entity query with the node entity:

$query = \Drupal::entityQuery('node')
  ->accessCheck(FALSE)
  ->condition('field_paragraph.entity.field_foo', 'bar');
I sit in a Tesla and translated this thread with Ai:

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.