src/Versioned.php
protected function augmentSQLStageUnique(SQLSelect $query, DataQuery $dataQuery)
    {
        if (!$this->hasStages()) {
            return;
        }
        // Set stage first
        $this->augmentSQLStage($query, $dataQuery);

        // Now exclude any ID from any other stage.
        $stage = $dataQuery->getQueryParam('Versioned.stage');
        $excludingStage = $stage === static::DRAFT ? static::LIVE : static::DRAFT;

        // Note that we double rename to avoid the regular stage rename
        // renaming all subquery references to be Versioned.stage
        $tempName = 'ExclusionarySource_' . $excludingStage;
        $excludingTable = $this->baseTable($excludingStage);
        $baseTable = $this->baseTable($stage);
        $query->addWhere("\"{$baseTable}\".\"ID\" NOT IN (SELECT \"ID\" FROM \"{$tempName}\")");
        $query->renameTable($tempName, $excludingTable);
    }
protected function augmentSQLStageUnique(SQLSelect $query, DataQuery $dataQuery)
    {
        if (!$this->hasStages()) {
            return;
        }
        // Set stage first
        $this->augmentSQLStage($query, $dataQuery);

        // Now exclude any ID from any other stage.
        $stage = $dataQuery->getQueryParam('Versioned.stage');
        $excludingStage = $stage === static::DRAFT ? static::LIVE : static::DRAFT;

        // Note that we double rename to avoid the regular stage rename
        // renaming all subquery references to be Versioned.stage
        $tempName = 'ExclusionarySource_' . $excludingStage;
        $excludingTable = $this->baseTable($excludingStage);
        $baseTable = $this->baseTable($stage);
        $query->addWhere("\"{$baseTable}\".\"ID\" NOT IN (SELECT \"ID\" FROM \"{$tempName}\")");
        $query->renameTable($tempName, $excludingTable);
    }
protected function augmentSQLStageUnique ( SQLSelect $ query , DataQuery $ dataQuery ) { if ( ! $ this -> hasStages ( ) ) { return ; } // Set stage first $ this -> augmentSQLStage ( $ query , $ dataQuery ) ; // Now exclude any ID from any other stage. $ stage = $ dataQuery -> getQueryParam ( 'Versioned.stage' ) ; $ excludingStage = $ stage === static :: DRAFT ? static :: LIVE : static :: DRAFT ; // Note that we double rename to avoid the regular stage rename // renaming all subquery references to be Versioned.stage $ tempName = 'ExclusionarySource_' . $ excludingStage ; $ excludingTable = $ this -> baseTable ( $ excludingStage ) ; $ baseTable = $ this -> baseTable ( $ stage ) ; $ query -> addWhere ( "\"{$baseTable}\".\"ID\" NOT IN (SELECT \"ID\" FROM \"{$tempName}\")" ) ; $ query -> renameTable ( $ tempName , $ excludingTable ) ; }
Reading a specific stage, but only return items that aren't in any other stage

@param SQLSelect $query
@param DataQuery $dataQuery
Reading a specific stage but only return items that aren t in any other stage