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@18: $this->sqlQuery->addExpression("COALESCE(workspace_association.target_entity_revision_id, base_table.$revision_field)", $revision_field); Chris@18: $this->sqlQuery->addExpression("base_table.$id_field", $id_field); Chris@18: Chris@18: $this->sqlGroupBy['workspace_association.target_entity_revision_id'] = 'workspace_association.target_entity_revision_id'; Chris@18: $this->sqlGroupBy["base_table.$id_field"] = "base_table.$id_field"; Chris@18: $this->sqlGroupBy["base_table.$revision_field"] = "base_table.$revision_field"; Chris@17: } Chris@17: Chris@17: return $this; Chris@17: } Chris@17: Chris@17: }