class ResultSetMappingBuilder extends ResultSetMapping (View source)

A ResultSetMappingBuilder uses the EntityManager to automatically populate entity fields.

Constants

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.

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.

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.

Properties

boolean $isMixed Whether the result is mixed (contains scalar values together with field values). from ResultSetMapping
boolean $isSelect Whether the result is a select statement. from ResultSetMapping
array $aliasMap Maps alias names to class names. from ResultSetMapping
array $relationMap Maps alias names to related association field names. from ResultSetMapping
array $parentAliasMap Maps alias names to parent alias names. from ResultSetMapping
array $fieldMappings Maps column names in the result set to field names for each class. from ResultSetMapping
array $scalarMappings Maps column names in the result set to the alias/field name to use in the mapped result. from ResultSetMapping
array $typeMappings Maps column names in the result set to the alias/field type to use in the mapped result. from ResultSetMapping
array $entityMappings Maps entities in the result set to the alias name to use in the mapped result. from ResultSetMapping
array $metaMappings Maps column names of meta columns (foreign keys, discriminator columns, . from ResultSetMapping
array $columnOwnerMap Maps column names in the result set to the alias they belong to. from ResultSetMapping
array $discriminatorColumns List of columns in the result set that are used as discriminator columns. from ResultSetMapping
array $indexByMap Maps alias names to field names that should be used for indexing. from ResultSetMapping
array $declaringClasses Map from column names to class names that declare the field the column is mapped to. from ResultSetMapping
array $isIdentifierColumn This is necessary to hydrate derivate foreign keys correctly. from ResultSetMapping
array $newObjectMappings Maps column names in the result set to field names for each new object expression. from ResultSetMapping
array $metadataParameterMapping Maps metadata parameter names to the metadata attribute. from ResultSetMapping
array $discriminatorParameters Contains query parameter names to be resolved as discriminator values from ResultSetMapping

Methods

addEntityResult(string $class, string $alias, string|null $resultAlias = null)

Adds an entity result to this ResultSetMapping.

setDiscriminatorColumn(string $alias, string $discrColumn)

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

addIndexBy(string $alias, string $fieldName)

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

addIndexByScalar(string $resultColumnName)

Sets to index by a scalar result column name.

addIndexByColumn(string $alias, string $resultColumnName)

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

boolean
hasIndexBy(string $alias)

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

boolean
isFieldResult(string $columnName)

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

addFieldResult(string $alias, string $columnName, string $fieldName, string|null $declaringClass = null)

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

addJoinedEntityResult(string $class, string $alias, string $parentAlias, string $relation)

Adds a joined entity result.

addScalarResult(string $columnName, string $alias, string $type = 'string')

Adds a scalar result mapping.

addMetadataParameterMapping(mixed $parameter, string $attribute)

Adds a metadata parameter mappings.

boolean
isScalarResult(string $columnName)

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

string
getClassName(string $alias)

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

string
getScalarAlias(string $columnName)

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

string
getDeclaringClass(string $columnName)

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

string
getRelation(string $alias)

No description

boolean
isRelation(string $alias)

No description

string
getEntityAlias(string $columnName)

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

string
getParentAlias(string $alias)

Gets the parent alias of the given alias.

boolean
hasParentAlias(string $alias)

Checks whether the given alias has a parent alias.

string
getFieldName(string $columnName)

Gets the field name for a column name.

array
getAliasMap()

No description

integer
getEntityResultCount()

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

boolean
isMixedResult()

Checks whether this ResultSetMapping defines a mixed result.

addMetaResult(string $alias, string $columnName, string $fieldName, bool $isIdentifierColumn = false, string $type = null)

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

__construct(EntityManagerInterface $em, integer $defaultRenameMode = self::COLUMN_RENAMING_NONE)

No description

void
addRootEntityFromClassMetadata(string $class, string $alias, array $renamedColumns = [], int|null $renameMode = null)

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

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

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

void
addAllClassFields(string $class, string $alias, array $columnAliasMap = [])

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

addNamedNativeQueryMapping(ClassMetadataInfo $class, array $queryMapping)

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

addNamedNativeQueryResultClassMapping(ClassMetadataInfo $class, string $resultClassName)

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

addNamedNativeQueryResultSetMapping(ClassMetadataInfo $class, string $resultSetMappingName)

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

addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classMetadata, array $entityMapping, string $alias)

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

string
generateSelectClause(array $tableAliases = [])

Generates the Select clause from this ResultSetMappingBuilder.

string
__toString()

No description

Details

ResultSetMapping addEntityResult(string $class, string $alias, string|null $resultAlias = null)

Adds an entity result to this ResultSetMapping.

Parameters

string $class The class name of the entity.
string $alias The alias for the class. The alias must be unique among all entity results or joined entity results within this ResultSetMapping.
string|null $resultAlias The result alias with which the entity result should be placed in the result structure.

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping setDiscriminatorColumn(string $alias, string $discrColumn)

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

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

Parameters

string $alias The alias of the entity result or joined entity result the discriminator column should be used for.
string $discrColumn The name of the discriminator column in the SQL result set.

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping addIndexBy(string $alias, string $fieldName)

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

Parameters

string $alias The alias of an entity result or joined entity result.
string $fieldName The name of the field to use for indexing.

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping addIndexByScalar(string $resultColumnName)

Sets to index by a scalar result column name.

Parameters

string $resultColumnName

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping addIndexByColumn(string $alias, string $resultColumnName)

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

Parameters

string $alias
string $resultColumnName

Return Value

ResultSetMapping This ResultSetMapping instance.

boolean hasIndexBy(string $alias)

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

Parameters

string $alias

Return Value

boolean

boolean isFieldResult(string $columnName)

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

Parameters

string $columnName The name of the column in the SQL result set.

Return Value

boolean

ResultSetMapping addFieldResult(string $alias, string $columnName, string $fieldName, string|null $declaringClass = null)

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

Parameters

string $alias The alias of the root entity or joined entity to which the field belongs.
string $columnName The name of the column in the SQL result set.
string $fieldName The name of the field on the declaring class.
string|null $declaringClass 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.

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping addJoinedEntityResult(string $class, string $alias, string $parentAlias, string $relation)

Adds a joined entity result.

Parameters

string $class The class name of the joined entity.
string $alias The unique alias to use for the joined entity.
string $parentAlias The alias of the entity result that is the parent of this joined result.
string $relation The association field that connects the parent entity result with the joined entity result.

Return Value

ResultSetMapping This ResultSetMapping instance.

ResultSetMapping addScalarResult(string $columnName, string $alias, string $type = 'string')

Adds a scalar result mapping.

Parameters

string $columnName The name of the column in the SQL result set.
string $alias The result alias with which the scalar result should be placed in the result structure.
string $type The column type

Return Value

ResultSetMapping This ResultSetMapping instance.

addMetadataParameterMapping(mixed $parameter, string $attribute)

Adds a metadata parameter mappings.

Parameters

mixed $parameter The parameter name in the SQL result set.
string $attribute The metadata attribute.

boolean isScalarResult(string $columnName)

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

Parameters

string $columnName The name of the column in the SQL result set.

Return Value

boolean

string getClassName(string $alias)

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

Parameters

string $alias

Return Value

string

string getScalarAlias(string $columnName)

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

Parameters

string $columnName The name of the column in the SQL result set.

Return Value

string

string getDeclaringClass(string $columnName)

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

Parameters

string $columnName

Return Value

string

string getRelation(string $alias)

Parameters

string $alias

Return Value

string

boolean isRelation(string $alias)

Parameters

string $alias

Return Value

boolean

string getEntityAlias(string $columnName)

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

Parameters

string $columnName

Return Value

string

string getParentAlias(string $alias)

Gets the parent alias of the given alias.

Parameters

string $alias

Return Value

string

boolean hasParentAlias(string $alias)

Checks whether the given alias has a parent alias.

Parameters

string $alias

Return Value

boolean

string getFieldName(string $columnName)

Gets the field name for a column name.

Parameters

string $columnName

Return Value

string

array getAliasMap()

Return Value

array

integer getEntityResultCount()

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

Return Value

integer

boolean isMixedResult()

Checks whether this ResultSetMapping defines a mixed result.

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 Value

boolean

ResultSetMapping addMetaResult(string $alias, string $columnName, string $fieldName, bool $isIdentifierColumn = false, string $type = null)

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

Parameters

string $alias The result alias with which the meta result should be placed in the result structure.
string $columnName The name of the column in the SQL result set.
string $fieldName The name of the field on the declaring class.
bool $isIdentifierColumn
string $type The column type

Return Value

ResultSetMapping This ResultSetMapping instance.

__construct(EntityManagerInterface $em, integer $defaultRenameMode = self::COLUMN_RENAMING_NONE)

Parameters

EntityManagerInterface $em
integer $defaultRenameMode

void addRootEntityFromClassMetadata(string $class, string $alias, array $renamedColumns = [], int|null $renameMode = null)

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

Parameters

string $class The class name of the root entity.
string $alias The unique alias to use for the root entity.
array $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName).
int|null $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).

Return Value

void

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

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

Parameters

string $class The class name of the joined entity.
string $alias The unique alias to use for the joined entity.
string $parentAlias The alias of the entity result that is the parent of this joined result.
string $relation The association field that connects the parent entity result with the joined entity result.
array $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName).
int|null $renameMode One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).

Return Value

void

protected void addAllClassFields(string $class, string $alias, array $columnAliasMap = [])

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

Parameters

string $class
string $alias
array $columnAliasMap

Return Value

void

Exceptions

InvalidArgumentException

ResultSetMappingBuilder addNamedNativeQueryMapping(ClassMetadataInfo $class, array $queryMapping)

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

Parameters

ClassMetadataInfo $class
array $queryMapping

Return Value

ResultSetMappingBuilder

ResultSetMappingBuilder addNamedNativeQueryResultClassMapping(ClassMetadataInfo $class, string $resultClassName)

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

Parameters

ClassMetadataInfo $class
string $resultClassName

Return Value

ResultSetMappingBuilder

ResultSetMappingBuilder addNamedNativeQueryResultSetMapping(ClassMetadataInfo $class, string $resultSetMappingName)

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

Parameters

ClassMetadataInfo $class
string $resultSetMappingName

Return Value

ResultSetMappingBuilder

ResultSetMappingBuilder addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classMetadata, array $entityMapping, string $alias)

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

Parameters

ClassMetadataInfo $classMetadata
array $entityMapping
string $alias

Return Value

ResultSetMappingBuilder

Exceptions

MappingException
InvalidArgumentException

string generateSelectClause(array $tableAliases = [])

Generates the Select clause from this ResultSetMappingBuilder.

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

Parameters

array $tableAliases

Return Value

string

string __toString()

Return Value

string