src/ORM/DataList.php
public function applyRelation($field, &$columnName = null, $linearOnly = false)
    {
        // If field is invalid, return it without modification
        if (!$this->isValidRelationName($field)) {
            $columnName = $field;
            return $this;
        }

        // Simple fields without relations are mapped directly
        if (strpos($field, '.') === false) {
            $columnName = '"' . $field . '"';
            return $this;
        }

        return $this->alterDataQuery(
            function (DataQuery $query) use ($field, &$columnName, $linearOnly) {
                $relations = explode('.', $field);
                $fieldName = array_pop($relations);

                // Apply relation
                $relationModelName = $query->applyRelation($relations, $linearOnly);
                $relationPrefix = $query->applyRelationPrefix($relations);

                // Find the db field the relation belongs to
                $columnName = DataObject::getSchema()
                    ->sqlColumnForField($relationModelName, $fieldName, $relationPrefix);
            }
        );
    }
public function applyRelation($field, &$columnName = null, $linearOnly = false)
    {
        // If field is invalid, return it without modification
        if (!$this->isValidRelationName($field)) {
            $columnName = $field;
            return $this;
        }

        // Simple fields without relations are mapped directly
        if (strpos($field, '.') === false) {
            $columnName = '"' . $field . '"';
            return $this;
        }

        return $this->alterDataQuery(
            function (DataQuery $query) use ($field, &$columnName, $linearOnly) {
                $relations = explode('.', $field);
                $fieldName = array_pop($relations);

                // Apply relation
                $relationModelName = $query->applyRelation($relations, $linearOnly);
                $relationPrefix = $query->applyRelationPrefix($relations);

                // Find the db field the relation belongs to
                $columnName = DataObject::getSchema()
                    ->sqlColumnForField($relationModelName, $fieldName, $relationPrefix);
            }
        );
    }
public function applyRelation ( $ field , & $ columnName = null , $ linearOnly = false ) { // If field is invalid, return it without modification if ( ! $ this -> isValidRelationName ( $ field ) ) { $ columnName = $ field ; return $ this ; } // Simple fields without relations are mapped directly if ( strpos ( $ field , '.' ) === false ) { $ columnName = '"' . $ field . '"' ; return $ this ; } return $ this -> alterDataQuery ( function ( DataQuery $ query ) use ( $ field , & $ columnName , $ linearOnly ) { $ relations = explode ( '.' , $ field ) ; $ fieldName = array_pop ( $ relations ) ; // Apply relation $ relationModelName = $ query -> applyRelation ( $ relations , $ linearOnly ) ; $ relationPrefix = $ query -> applyRelationPrefix ( $ relations ) ; // Find the db field the relation belongs to $ columnName = DataObject :: getSchema ( ) -> sqlColumnForField ( $ relationModelName , $ fieldName , $ relationPrefix ) ; } ) ; }
Given a field or relation name, apply it safely to this datalist.

Unlike getRelationName, this is immutable and will fallback to the quoted field
name if not a relation.

@param string $field Name of field or relation to apply
@param string &$columnName Quoted column name
@param bool $linearOnly Set to true to restrict to linear relations only. Set this
if this relation will be used for sorting, and should not include duplicate rows.
@return $this DataList with this relation applied
Given a field or relation name apply it safely to this datalist .