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->entity->id()
.
public function preSave() {
if ($this->hasNewEntity()) {
// Save the entity if it has not already been saved by some other code.
if ($this->entity->isNew()) {
$this->entity->save();
}
// Make sure the parent knows we are updating this property so it can
// react properly.
$this->target_id = $this->entity->id();
}
if (!$this->isEmpty() && $this->target_id === NULL) {
$this->target_id = $this->entity->id();
}
}
I take your code should be changed to the following one.
$entity_ids = $query
->condition('type', 'user')
->condition('status', 1)
->condition('field_product_document', $node->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.
$node->getTitle()
? I would guess the reference is using the node ID. not the title.