diff --git a/lib/Doctrine/ORM/Query/Expr/From.php b/lib/Doctrine/ORM/Query/Expr/From.php index 6646e1de2..a4ad22c3f 100644 --- a/lib/Doctrine/ORM/Query/Expr/From.php +++ b/lib/Doctrine/ORM/Query/Expr/From.php @@ -34,27 +34,54 @@ namespace Doctrine\ORM\Query\Expr; */ class From { + /** + * @var string + */ private $_from; + + /** + * @var string + */ private $_alias; - - public function __construct($from, $alias) + + /** + * @var string + */ + private $_indexBy; + + /** + * @param string $from The class name. + * @param string $alias The alias of the class. + * @param string $indexBy The index for the from. + */ + public function __construct($from, $alias, $indexBy = null) { - $this->_from = $from; - $this->_alias = $alias; + $this->_from = $from; + $this->_alias = $alias; + $this->_indexBy = $indexBy; } - + + /** + * @return string + */ public function getFrom() { return $this->_from; } + /** + * @return string + */ public function getAlias() { return $this->_alias; } + /** + * @return string + */ public function __toString() { - return $this->_from . ' ' . $this->_alias; + return $this->_from . ' ' . $this->_alias . ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : ''); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index 9b2829408..f5914fd57 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -595,9 +595,10 @@ class QueryBuilder * * @param string $from The class name. * @param string $alias The alias of the class. + * @param string $indexBy The index for the from. * @return QueryBuilder This QueryBuilder instance. */ - public function from($from, $alias) + public function from($from, $alias,$indexBy = null) { return $this->add('from', new Expr\From($from, $alias), true); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php new file mode 100644 index 000000000..3bd478a45 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1335Test.php @@ -0,0 +1,60 @@ +_em->getClassMetadata(__NAMESPACE__ . '\DDC1135User') + ); + + try { + $this->_schemaTool->dropSchema($classes); + $this->_schemaTool->createSchema($classes); + } catch(\Exception $e) { + + } + } + + + public function testTicket() + { + $this->markTestIncomplete(); + + $builder = $this->_em->createQueryBuilder(); + $builder->select('u')->from('Doctrine\Tests\ORM\Functional\Ticket\DDC1135User', 'u', 'u.id'); + + + $sql = $builder->getQuery()->getSQL(); + + $this->assertEquals('SELECT d0_.id AS id0, d0_.name AS name1 FROM DDC1135User INDEX BY d0_.id', $sql); + } + +} + +/** + * @Entity + */ +class DDC1135User +{ + + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + protected $id; + + /** + * @Column(type="string", length=255) + */ + protected $name; + +} \ No newline at end of file