src/ORM/DataQuery.php
protected function joinHasOneRelation(
        $localClass,
        $localField,
        $foreignClass,
        $localPrefix = null,
        $foreignPrefix = null
    ) {
        if (!$foreignClass) {
            throw new InvalidArgumentException("Could not find a has_one relationship {$localField} on {$localClass}");
        }

        if ($foreignClass === DataObject::class) {
            throw new InvalidArgumentException(
                "Could not join polymorphic has_one relationship {$localField} on {$localClass}"
            );
        }
        $schema = DataObject::getSchema();

        // Skip if already joined
        $foreignBaseClass = $schema->baseDataClass($foreignClass);
        $foreignBaseTable = $schema->tableName($foreignBaseClass);
        if ($this->query->isJoinedTo($foreignPrefix . $foreignBaseTable)) {
            return;
        }

        // Join base table
        $foreignIDColumn = $schema->sqlColumnForField($foreignBaseClass, 'ID', $foreignPrefix);
        $localColumn = $schema->sqlColumnForField($localClass, "{$localField}ID", $localPrefix);
        $this->query->addLeftJoin(
            $foreignBaseTable,
            "{$foreignIDColumn} = {$localColumn}",
            $foreignPrefix . $foreignBaseTable
        );

        // Add join clause to the component's ancestry classes so that the search filter could search on
        // its ancestor fields.
        $ancestry = ClassInfo::ancestry($foreignClass, true);
        if (!empty($ancestry)) {
            $ancestry = array_reverse($ancestry);
            foreach ($ancestry as $ancestor) {
                $ancestorTable = $schema->tableName($ancestor);
                if ($ancestorTable !== $foreignBaseTable) {
                    $ancestorTableAliased = $foreignPrefix . $ancestorTable;
                    $this->query->addLeftJoin(
                        $ancestorTable,
                        "{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
                        $ancestorTableAliased
                    );
                }
            }
        }
    }
protected function joinHasOneRelation(
        $localClass,
        $localField,
        $foreignClass,
        $localPrefix = null,
        $foreignPrefix = null
    ) {
        if (!$foreignClass) {
            throw new InvalidArgumentException("Could not find a has_one relationship {$localField} on {$localClass}");
        }

        if ($foreignClass === DataObject::class) {
            throw new InvalidArgumentException(
                "Could not join polymorphic has_one relationship {$localField} on {$localClass}"
            );
        }
        $schema = DataObject::getSchema();

        // Skip if already joined
        $foreignBaseClass = $schema->baseDataClass($foreignClass);
        $foreignBaseTable = $schema->tableName($foreignBaseClass);
        if ($this->query->isJoinedTo($foreignPrefix . $foreignBaseTable)) {
            return;
        }

        // Join base table
        $foreignIDColumn = $schema->sqlColumnForField($foreignBaseClass, 'ID', $foreignPrefix);
        $localColumn = $schema->sqlColumnForField($localClass, "{$localField}ID", $localPrefix);
        $this->query->addLeftJoin(
            $foreignBaseTable,
            "{$foreignIDColumn} = {$localColumn}",
            $foreignPrefix . $foreignBaseTable
        );

        // Add join clause to the component's ancestry classes so that the search filter could search on
        // its ancestor fields.
        $ancestry = ClassInfo::ancestry($foreignClass, true);
        if (!empty($ancestry)) {
            $ancestry = array_reverse($ancestry);
            foreach ($ancestry as $ancestor) {
                $ancestorTable = $schema->tableName($ancestor);
                if ($ancestorTable !== $foreignBaseTable) {
                    $ancestorTableAliased = $foreignPrefix . $ancestorTable;
                    $this->query->addLeftJoin(
                        $ancestorTable,
                        "{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"",
                        $ancestorTableAliased
                    );
                }
            }
        }
    }
protected function joinHasOneRelation ( $ localClass , $ localField , $ foreignClass , $ localPrefix = null , $ foreignPrefix = null ) { if ( ! $ foreignClass ) { throw new InvalidArgumentException ( "Could not find a has_one relationship {$localField} on {$localClass}" ) ; } if ( $ foreignClass === DataObject :: class ) { throw new InvalidArgumentException ( "Could not join polymorphic has_one relationship {$localField} on {$localClass}" ) ; } $ schema = DataObject :: getSchema ( ) ; // Skip if already joined $ foreignBaseClass = $ schema -> baseDataClass ( $ foreignClass ) ; $ foreignBaseTable = $ schema -> tableName ( $ foreignBaseClass ) ; if ( $ this -> query -> isJoinedTo ( $ foreignPrefix . $ foreignBaseTable ) ) { return ; } // Join base table $ foreignIDColumn = $ schema -> sqlColumnForField ( $ foreignBaseClass , 'ID' , $ foreignPrefix ) ; $ localColumn = $ schema -> sqlColumnForField ( $ localClass , "{$localField}ID" , $ localPrefix ) ; $ this -> query -> addLeftJoin ( $ foreignBaseTable , "{$foreignIDColumn} = {$localColumn}" , $ foreignPrefix . $ foreignBaseTable ) ; // Add join clause to the component's ancestry classes so that the search filter could search on // its ancestor fields. $ ancestry = ClassInfo :: ancestry ( $ foreignClass , true ) ; if ( ! empty ( $ ancestry ) ) { $ ancestry = array_reverse ( $ ancestry ) ; foreach ( $ ancestry as $ ancestor ) { $ ancestorTable = $ schema -> tableName ( $ ancestor ) ; if ( $ ancestorTable !== $ foreignBaseTable ) { $ ancestorTableAliased = $ foreignPrefix . $ ancestorTable ; $ this -> query -> addLeftJoin ( $ ancestorTable , "{$foreignIDColumn} = \"{$ancestorTableAliased}\".\"ID\"" , $ ancestorTableAliased ) ; } } } }
Join the given class to this query with the given key

@param string $localClass Name of class that has the has_one to the joined class
@param string $localField Name of the has_one relationship to joi
@param string $foreignClass Class to join
@param string $localPrefix Table prefix to use for local class
@param string $foreignPrefix Table prefix to use for joined table
Join the given class to this query with the given key