Chris@17: traitPrepare(); Chris@17: Chris@17: // If the prepare() method from the trait decided that we need to alter this Chris@17: // query, we need to re-define the the key fields for fetchAllKeyed() as SQL Chris@17: // expressions. Chris@17: if ($this->sqlQuery->getMetaData('active_workspace_id')) { Chris@17: $id_field = $this->entityType->getKey('id'); Chris@17: $revision_field = $this->entityType->getKey('revision'); Chris@17: Chris@17: // Since the query is against the base table, we have to take into account Chris@17: // that the revision ID might come from the workspace_association Chris@17: // relationship, and, as a consequence, the revision ID field is no longer Chris@17: // a simple SQL field but an expression. Chris@17: $this->sqlFields = []; Chris@17: $this->sqlExpressions[$revision_field] = "COALESCE(workspace_association.target_entity_revision_id, base_table.$revision_field)"; Chris@17: $this->sqlExpressions[$id_field] = "base_table.$id_field"; Chris@17: } Chris@17: Chris@17: return $this; Chris@17: } Chris@17: Chris@17: /** Chris@17: * {@inheritdoc} Chris@17: */ Chris@17: protected function finish() { Chris@17: foreach ($this->sqlExpressions as $alias => $expression) { Chris@17: $this->sqlQuery->addExpression($expression, $alias); Chris@17: } Chris@17: return parent::finish(); Chris@17: } Chris@17: Chris@17: }