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

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

bool
hasIndexBy(string $alias)

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

bool
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, Type $type)

Adds a scalar result mapping.

bool
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.

getRelation(string $alias)

No description

bool
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.

bool
hasParentAlias(string $alias)

Checks whether the given alias has a parent alias.

string
getFieldName(string $columnName)

Gets the field name for a column name.

string[]
getAliasMap()

No description

int
getEntityResultCount()

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

bool
isMixedResult()

Checks whether this ResultSetMapping defines a mixed result.

addMetaResult(string $alias, string $columnName, string $fieldName, bool $isIdentifierColumn, Type $type)

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

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

No description

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

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

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.

addAllClassFields(string $class, string $alias, array $customRenameColumns, int $renameMode)

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

string
generateSelectClause(string[] $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.

bool 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

bool

bool 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

bool

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, Type $type)

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.
Type $type The column type

Return Value

ResultSetMapping This ResultSetMapping instance.

bool 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

bool

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

AssociationMetadata getRelation(string $alias)

Parameters

string $alias

Return Value

AssociationMetadata

bool isRelation(string $alias)

Parameters

string $alias

Return Value

bool

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

bool hasParentAlias(string $alias)

Checks whether the given alias has a parent alias.

Parameters

string $alias

Return Value

bool

string getFieldName(string $columnName)

Gets the field name for a column name.

Parameters

string $columnName

Return Value

string

string[] getAliasMap()

Return Value

string[]

int getEntityResultCount()

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

Return Value

int

bool 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

bool

ResultSetMapping addMetaResult(string $alias, string $columnName, string $fieldName, bool $isIdentifierColumn, Type $type)

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
Type $type The column type

Return Value

ResultSetMapping This ResultSetMapping instance.

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

Parameters

EntityManagerInterface $em
$defaultRenameMode

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).

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).

protected addAllClassFields(string $class, string $alias, array $customRenameColumns, int $renameMode)

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

Parameters

string $class
string $alias
array $customRenameColumns
int $renameMode

Exceptions

InvalidArgumentException

string generateSelectClause(string[] $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

string[] $tableAliases

Return Value

string

string __toString()

Return Value

string