Get parent of an entity reference I have an entity reference inside node. How can I retrieve the parent node?

I tried with the following code, where $node is my entity reference, but it doesn't work.

$entity_ids = $query
    -&gt;condition('type', 'user')
    -&gt;condition('status', 1)
    -&gt;condition('field_product_document', $node-&gt;getTitle(),'CONTAINS');


What is wrong in the code? What code should I use?
An entity reference field is implemented from the \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem class. If you look at the code for EntityReferenceItem::preSave(), you will notice it is setting its target_id property to $this-&gt;entity-&gt;id().

public function preSave() {
  if ($this-&gt;hasNewEntity()) {
    // Save the entity if it has not already been saved by some other code.
    if ($this-&gt;entity-&gt;isNew()) {
      $this-&gt;entity-&gt;save();
    }
    // Make sure the parent knows we are updating this property so it can
    // react properly.
    $this-&gt;target_id = $this-&gt;entity-&gt;id();
  }
  if (!$this-&gt;isEmpty() &amp;&amp; $this-&gt;target_id === NULL) {
    $this-&gt;target_id = $this-&gt;entity-&gt;id();
  }
}


I take your code should be changed to the following one.

$entity_ids = $query
    -&gt;condition('type', 'user')
    -&gt;condition('status', 1)
    -&gt;condition('field_product_document', $node-&gt;id());


The change makes also sense: A node title cannot be used to uniquely identify a node, since there could be more nodes with the same title; the node ID uniquely identify a node on a Drupal site.