1
0
mirror of synced 2025-03-05 04:13:20 +03:00

More prominent note about ResultSetMappingBuilder in native-sql chapter

This commit is contained in:
Benjamin Eberlei 2012-04-10 23:16:51 +02:00
parent 01381fae1f
commit e168b4e543

View File

@ -9,6 +9,10 @@ of the database result should be mapped by Doctrine in terms of the
object graph. This allows you to map arbitrary SQL code to objects, object graph. This allows you to map arbitrary SQL code to objects,
such as highly vendor-optimized SQL or stored-procedures. such as highly vendor-optimized SQL or stored-procedures.
Because writing ``ResultSetMapping`` is not so simple, there is a convenience
wrapper around it called a ``ResultSetMappingBuilder``. The last section
of this chapter describes its usage.
.. note:: .. note::
If you want to execute DELETE, UPDATE or INSERT statements If you want to execute DELETE, UPDATE or INSERT statements
@ -377,13 +381,16 @@ in your sQL statement:
<?php <?php
use Doctrine\ORM\Query\ResultSetMappingBuilder;
$sql = "SELECT u.id, u.name, a.id AS address_id, a.street, a.city " . $sql = "SELECT u.id, u.name, a.id AS address_id, a.street, a.city " .
"FROM users u INNER JOIN address a ON u.address_id = a.id"; "FROM users u INNER JOIN address a ON u.address_id = a.id";
$rsm = new ResultSetMappingBuilder($em); $rsm = new ResultSetMappingBuilder($entityManager);
$rsm->addRootEntityFromClassMetadata('MyProject\User', 'u'); $rsm->addRootEntityFromClassMetadata('MyProject\User', 'u');
$rsm->addJoinedEntityFromClassMetadata('MyProject\Address', 'a', 'u', 'address', array('id' => 'address_id')); $rsm->addJoinedEntityFromClassMetadata('MyProject\Address', 'a', 'u', 'address', array('id' => 'address_id'));
For entites with more columns the builder is very convenient to use. It extends the ``ResultSetMapping`` class For entites with more columns the builder is very convenient to use. It extends the ``ResultSetMapping`` class
and as such has all the functionality of it as well. Currently the ``ResultSetMappingBuilder`` does not support and as such has all the functionality of it as well. Currently the ``ResultSetMappingBuilder`` does not support
entities with inheritance. entities with inheritance.