Documentation

ResultSetMappingBuilder extends ResultSetMapping
in package
Uses SQLResultCasing

A ResultSetMappingBuilder uses the EntityManager to automatically populate entity fields.

Table of Contents

Constants

COLUMN_RENAMING_CUSTOM  = 2
Picking custom renaming allows the user to define the renaming of specific columns with a rename array that contains column names as keys and result alias as values.
COLUMN_RENAMING_INCREMENT  = 3
Incremental renaming uses a result set mapping internal counter to add a number to each column result, leading to uniqueness. This only works if you use {@see generateSelectClause()} to generate the SELECT clause for you.
COLUMN_RENAMING_NONE  = 1
Picking this rename mode will register entity columns as is, as they are in the database. This can cause clashes when multiple entities are fetched that have columns with the same name.

Properties

$discriminatorParameters  : mixed
Contains query parameter names to be resolved as discriminator values
$isIdentifierColumn  : mixed
This is necessary to hydrate derivate foreign keys correctly.
$metadataParameterMapping  : mixed
Maps metadata parameter names to the metadata attribute.
$newObjectMappings  : mixed
Maps column names in the result set to field names for each new object expression.
$defaultRenameMode  : int
Default column renaming mode.
$em  : EntityManagerInterface
$sqlCounter  : int

Methods

__construct()  : mixed
__toString()  : string
addEntityResult()  : $this
Adds an entity result to this ResultSetMapping.
addEnumResult()  : $this
Adds a scalar result mapping.
addFieldResult()  : $this
Adds a field to the result that belongs to an entity or joined entity.
addIndexBy()  : $this
Sets a field to use for indexing an entity result or joined entity result.
addIndexByColumn()  : $this
Sets a column to use for indexing an entity or joined entity result by the given alias name.
addIndexByScalar()  : $this
Sets to index by a scalar result column name.
addJoinedEntityFromClassMetadata()  : void
Adds a joined entity and all of its fields to the result set.
addJoinedEntityResult()  : $this
Adds a joined entity result.
addMetadataParameterMapping()  : void
Adds a metadata parameter mappings.
addMetaResult()  : $this
Adds a meta column (foreign key or discriminator column) to the result set.
addNamedNativeQueryEntityResultMapping()  : $this
Adds the entity result mapping of the results of native SQL queries to the result set.
addNamedNativeQueryMapping()  : ResultSetMappingBuilder
Adds the mappings of the results of native SQL queries to the result set.
addNamedNativeQueryResultClassMapping()  : $this
Adds the class mapping of the results of native SQL queries to the result set.
addNamedNativeQueryResultSetMapping()  : $this
Adds the result set mapping of the results of native SQL queries to the result set.
addRootEntityFromClassMetadata()  : void
Adds a root entity and all of its fields to the result set.
addScalarResult()  : $this
Adds a scalar result mapping.
generateSelectClause()  : string
Generates the Select clause from this ResultSetMappingBuilder.
getAliasMap()  : mixed
getClassName()  : class-string
Gets the name of the class of an entity result or joined entity result, identified by the given unique alias.
getDeclaringClass()  : class-string
Gets the name of the class that owns a field mapping for the specified column.
getEntityAlias()  : string
Gets the alias of the class that owns a field mapping for the specified column.
getEntityResultCount()  : int
Gets the number of different entities that appear in the mapped result.
getFieldName()  : string
Gets the field name for a column name.
getParentAlias()  : string
Gets the parent alias of the given alias.
getRelation()  : string
getScalarAlias()  : string|int
Gets the field alias for a column that is mapped as a scalar value.
hasIndexBy()  : bool
Checks whether an entity result or joined entity result with a given alias has a field set for indexing.
hasParentAlias()  : bool
Checks whether the given alias has a parent alias.
isFieldResult()  : bool
Checks whether the column with the given name is mapped as a field result as part of an entity result or joined entity result.
isMixedResult()  : bool
Checks whether this ResultSetMapping defines a mixed result.
isRelation()  : bool
isScalarResult()  : bool
Checks whether a column with a given name is mapped as a scalar result.
setDiscriminatorColumn()  : $this
Sets a discriminator column for an entity result or joined entity result.
addAllClassFields()  : void
Adds all fields of the given class to the result set mapping (columns and meta fields).
getColumnAlias()  : string
Gets column alias for a given column.
getColumnAliasMap()  : array<string|int, string>
Retrieves a class columns and join columns aliases that are used in the SELECT clause.
isInheritanceSupported()  : bool

Constants

COLUMN_RENAMING_CUSTOM

Picking custom renaming allows the user to define the renaming of specific columns with a rename array that contains column names as keys and result alias as values.

public mixed COLUMN_RENAMING_CUSTOM = 2

COLUMN_RENAMING_INCREMENT

Incremental renaming uses a result set mapping internal counter to add a number to each column result, leading to uniqueness. This only works if you use {@see generateSelectClause()} to generate the SELECT clause for you.

public mixed COLUMN_RENAMING_INCREMENT = 3

COLUMN_RENAMING_NONE

Picking this rename mode will register entity columns as is, as they are in the database. This can cause clashes when multiple entities are fetched that have columns with the same name.

public mixed COLUMN_RENAMING_NONE = 1

Properties

$discriminatorParameters

Contains query parameter names to be resolved as discriminator values

public mixed $discriminatorParameters = []
Tags
psalm-var

array<string, string>

$isIdentifierColumn

This is necessary to hydrate derivate foreign keys correctly.

public mixed $isIdentifierColumn = []
Tags
psalm-var

array<string, array<string, bool>>

$metadataParameterMapping

Maps metadata parameter names to the metadata attribute.

public mixed $metadataParameterMapping = []
Tags
psalm-var

array<int|string, string>

$newObjectMappings

Maps column names in the result set to field names for each new object expression.

public mixed $newObjectMappings = []
Tags
psalm-var

array<string, array<string, mixed>>

$defaultRenameMode

Default column renaming mode.

private int $defaultRenameMode
Tags
psalm-var

self::COLUMN_RENAMING_*

Methods

addEntityResult()

Adds an entity result to this ResultSetMapping.

public addEntityResult(string $class, string $alias[, string|null $resultAlias = null ]) : $this
Parameters
$class : string

The class name of the entity.

$alias : string

The alias for the class. The alias must be unique among all entity results or joined entity results within this ResultSetMapping.

$resultAlias : string|null = null

The result alias with which the entity result should be placed in the result structure.

Tags
psalm-param

class-string $class

todo

Rename: addRootEntity

Return values
$this

addEnumResult()

Adds a scalar result mapping.

public addEnumResult(string $columnName, string $enumType) : $this
Parameters
$columnName : string

The name of the column in the SQL result set.

$enumType : string

The enum type

Return values
$this

addFieldResult()

Adds a field to the result that belongs to an entity or joined entity.

public addFieldResult(string $alias, string $columnName, string $fieldName[, string|null $declaringClass = null ]) : $this
Parameters
$alias : string

The alias of the root entity or joined entity to which the field belongs.

$columnName : string

The name of the column in the SQL result set.

$fieldName : string

The name of the field on the declaring class.

$declaringClass : string|null = null

The name of the class that declares/owns the specified field. When $alias refers to a superclass in a mapped hierarchy but the field $fieldName is defined on a subclass, specify that here. If not specified, the field is assumed to belong to the class designated by $alias.

Tags
psalm-param

class-string|null $declaringClass

todo

Rename: addField

Return values
$this

addIndexBy()

Sets a field to use for indexing an entity result or joined entity result.

public addIndexBy(string $alias, string $fieldName) : $this
Parameters
$alias : string

The alias of an entity result or joined entity result.

$fieldName : string

The name of the field to use for indexing.

Return values
$this

addIndexByColumn()

Sets a column to use for indexing an entity or joined entity result by the given alias name.

public addIndexByColumn(string $alias, string $resultColumnName) : $this
Parameters
$alias : string
$resultColumnName : string
Return values
$this

addIndexByScalar()

Sets to index by a scalar result column name.

public addIndexByScalar(string $resultColumnName) : $this
Parameters
$resultColumnName : string
Return values
$this

addJoinedEntityFromClassMetadata()

Adds a joined entity and all of its fields to the result set.

public addJoinedEntityFromClassMetadata(string $class, string $alias, string $parentAlias, string $relation[, array<string|int, string> $renamedColumns = [] ][, int|null $renameMode = null ]) : void
Parameters
$class : string

The class name of the joined entity.

$alias : string

The unique alias to use for the joined entity.

$parentAlias : string

The alias of the entity result that is the parent of this joined result.

$relation : string

The association field that connects the parent entity result with the joined entity result.

$renamedColumns : array<string|int, string> = []

Columns that have been renamed (tableColumnName => queryColumnName).

$renameMode : int|null = null

One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).

Tags
psalm-param

class-string $class

psalm-param

array<string, string> $renamedColumns

psalm-param

self::COLUMN_RENAMING_*|null $renameMode

addJoinedEntityResult()

Adds a joined entity result.

public addJoinedEntityResult(string $class, string $alias, string $parentAlias, string $relation) : $this
Parameters
$class : string

The class name of the joined entity.

$alias : string

The unique alias to use for the joined entity.

$parentAlias : string

The alias of the entity result that is the parent of this joined result.

$relation : string

The association field that connects the parent entity result with the joined entity result.

Tags
psalm-param

class-string $class

todo

Rename: addJoinedEntity

Return values
$this

addMetadataParameterMapping()

Adds a metadata parameter mappings.

public addMetadataParameterMapping(string|int $parameter, string $attribute) : void
Parameters
$parameter : string|int

The parameter name in the SQL result set.

$attribute : string

The metadata attribute.

addMetaResult()

Adds a meta column (foreign key or discriminator column) to the result set.

public addMetaResult(string $alias, string $columnName, string $fieldName[, bool $isIdentifierColumn = false ][, string|null $type = null ]) : $this
Parameters
$alias : string

The result alias with which the meta result should be placed in the result structure.

$columnName : string

The name of the column in the SQL result set.

$fieldName : string

The name of the field on the declaring class.

$isIdentifierColumn : bool = false
$type : string|null = null

The column type

Tags
todo

Make all methods of this class require all parameters and not infer anything

Return values
$this

addNamedNativeQueryEntityResultMapping()

Adds the entity result mapping of the results of native SQL queries to the result set.

public addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classMetadata, array<string|int, mixed> $entityMapping, string $alias) : $this
Parameters
$classMetadata : ClassMetadataInfo
$entityMapping : array<string|int, mixed>
$alias : string
Tags
deprecated

This method is deprecated and will be removed in Doctrine ORM 3.0.

throws
MappingException
throws
InvalidArgumentException
Return values
$this

addNamedNativeQueryResultClassMapping()

Adds the class mapping of the results of native SQL queries to the result set.

public addNamedNativeQueryResultClassMapping(ClassMetadataInfo $class, string $resultClassName) : $this
Parameters
$class : ClassMetadataInfo
$resultClassName : string
Tags
deprecated

This method is deprecated and will be removed in Doctrine ORM 3.0.

Return values
$this

addNamedNativeQueryResultSetMapping()

Adds the result set mapping of the results of native SQL queries to the result set.

public addNamedNativeQueryResultSetMapping(ClassMetadataInfo $class, string $resultSetMappingName) : $this
Parameters
$class : ClassMetadataInfo
$resultSetMappingName : string
Tags
deprecated

This method is deprecated and will be removed in Doctrine ORM 3.0.

Return values
$this

addRootEntityFromClassMetadata()

Adds a root entity and all of its fields to the result set.

public addRootEntityFromClassMetadata(string $class, string $alias[, array<string|int, string> $renamedColumns = [] ][, int|null $renameMode = null ]) : void
Parameters
$class : string

The class name of the root entity.

$alias : string

The unique alias to use for the root entity.

$renamedColumns : array<string|int, string> = []

Columns that have been renamed (tableColumnName => queryColumnName).

$renameMode : int|null = null

One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).

Tags
psalm-param

class-string $class

psalm-param

array<string, string> $renamedColumns

psalm-param

self::COLUMN_RENAMING_*|null $renameMode

addScalarResult()

Adds a scalar result mapping.

public addScalarResult(string $columnName, string|int $alias[, string $type = 'string' ]) : $this
Parameters
$columnName : string

The name of the column in the SQL result set.

$alias : string|int

The result alias with which the scalar result should be placed in the result structure.

$type : string = 'string'

The column type

Tags
todo

Rename: addScalar

Return values
$this

generateSelectClause()

Generates the Select clause from this ResultSetMappingBuilder.

public generateSelectClause([array<string|int, string> $tableAliases = [] ]) : string

Works only for all the entity results. The select parts for scalar expressions have to be written manually.

Parameters
$tableAliases : array<string|int, string> = []
Tags
psalm-param

array<string, string> $tableAliases

Return values
string

getAliasMap()

public getAliasMap() : mixed
Tags
psalm-return

array<string, class-string>

getClassName()

Gets the name of the class of an entity result or joined entity result, identified by the given unique alias.

public getClassName(string $alias) : class-string
Parameters
$alias : string
Return values
class-string

getDeclaringClass()

Gets the name of the class that owns a field mapping for the specified column.

public getDeclaringClass(string $columnName) : class-string
Parameters
$columnName : string
Return values
class-string

getEntityAlias()

Gets the alias of the class that owns a field mapping for the specified column.

public getEntityAlias(string $columnName) : string
Parameters
$columnName : string
Return values
string

getEntityResultCount()

Gets the number of different entities that appear in the mapped result.

public getEntityResultCount() : int
Tags
psalm-return

0|positive-int

Return values
int

getFieldName()

Gets the field name for a column name.

public getFieldName(string $columnName) : string
Parameters
$columnName : string
Return values
string

getParentAlias()

Gets the parent alias of the given alias.

public getParentAlias(string $alias) : string
Parameters
$alias : string
Return values
string

getRelation()

public getRelation(string $alias) : string
Parameters
$alias : string
Return values
string

getScalarAlias()

Gets the field alias for a column that is mapped as a scalar value.

public getScalarAlias(string $columnName) : string|int
Parameters
$columnName : string

The name of the column in the SQL result set.

Return values
string|int

hasIndexBy()

Checks whether an entity result or joined entity result with a given alias has a field set for indexing.

public hasIndexBy(string $alias) : bool
Parameters
$alias : string
Tags
todo

Rename: isIndexed($alias)

Return values
bool

hasParentAlias()

Checks whether the given alias has a parent alias.

public hasParentAlias(string $alias) : bool
Parameters
$alias : string
Return values
bool

isFieldResult()

Checks whether the column with the given name is mapped as a field result as part of an entity result or joined entity result.

public isFieldResult(string $columnName) : bool
Parameters
$columnName : string

The name of the column in the SQL result set.

Tags
todo

Rename: isField

Return values
bool

isMixedResult()

Checks whether this ResultSetMapping defines a mixed result.

public isMixedResult() : bool

Mixed results can only occur in object and array (graph) hydration. In such a case a mixed result means that scalar values are mixed with objects/array in the result.

Return values
bool

isRelation()

public isRelation(string $alias) : bool
Parameters
$alias : string
Return values
bool

isScalarResult()

Checks whether a column with a given name is mapped as a scalar result.

public isScalarResult(string $columnName) : bool
Parameters
$columnName : string

The name of the column in the SQL result set.

Tags
todo

Rename: isScalar

Return values
bool

setDiscriminatorColumn()

Sets a discriminator column for an entity result or joined entity result.

public setDiscriminatorColumn(string $alias, string $discrColumn) : $this

The discriminator column will be used to determine the concrete class name to instantiate.

Parameters
$alias : string

The alias of the entity result or joined entity result the discriminator column should be used for.

$discrColumn : string

The name of the discriminator column in the SQL result set.

Tags
todo

Rename: addDiscriminatorColumn

Return values
$this

addAllClassFields()

Adds all fields of the given class to the result set mapping (columns and meta fields).

protected addAllClassFields(string $class, string $alias[, array<string|int, string> $columnAliasMap = [] ]) : void
Parameters
$class : string
$alias : string
$columnAliasMap : array<string|int, string> = []
Tags
psalm-param

array<string, string> $columnAliasMap

throws
InvalidArgumentException

getColumnAlias()

Gets column alias for a given column.

private getColumnAlias(string $columnName, int $mode, array<string|int, mixed> $customRenameColumns) : string
Parameters
$columnName : string
$mode : int
$customRenameColumns : array<string|int, mixed>
Tags
psalm-param

array<string, string> $customRenameColumns

psalm-assert

self::COLUMN_RENAMING_* $mode

Return values
string

getColumnAliasMap()

Retrieves a class columns and join columns aliases that are used in the SELECT clause.

private getColumnAliasMap(string $className, int $mode, array<string|int, mixed> $customRenameColumns) : array<string|int, string>

This depends on the renaming mode selected by the user.

Parameters
$className : string
$mode : int
$customRenameColumns : array<string|int, mixed>
Tags
psalm-param

class-string $className

psalm-param

self::COLUMN_RENAMING_* $mode

psalm-param

array<string, string> $customRenameColumns

psalm-return

array<array-key, string>

Return values
array<string|int, string>

        
On this page

Search results